有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java采用了更实用的方法

我目前有这个方法(这基本上是真实的,我刚刚重命名了变量和对象)

private void myMethod(
      final InputMessage inputMessage,
      final String id) {
    try {
        final Map<String, String> result =
              jdbcTemplate.query(
                  QUERY /* sql */, 
                  ROW_EXTRACTOR /* ResultSetExtractor */, 
                  id /* args */
              );

        if (result != null) {
            inputMessage.setParam1(result.get("param1"));
            inputMessage.setId(result.get("description")); // Insert description
            return;
        }
    } catch (final Exception e) {
        logger.error(...);
    }

    final String param1 = ...

    inputMessage.setParam1(param1);
    inputMessage.setId(id); // Insert the ID
}

我想用一种更实用的方法来解决这个问题。只是尝试一下
我考虑过不同的解决方案,但没有一个能保持相同的逻辑

你会怎么做?有可能吗
我在Java 8上,但如果需要,您可以加入Java 11类和方法

不需要“转换”整个方法,我更感兴趣的是result提取后的部分。然而,它与try - catch块紧密耦合


共 (0) 个答案