Java 如何从executeFunction访问多个返回值?

Java 如何从executeFunction访问多个返回值?,java,jdbc,spring-jdbc,Java,Jdbc,Spring Jdbc,我已经看到了许多从simpleJdbcCall.executeFunction获取单个原语结果的示例。我需要知道如何访问一组结果执行返回一个映射。您必须向executeFunction提供SqlOutParameter,并告诉它要返回的类型。我将返回映射到MyCustomClass.class,它返回null。我知道函数将返回3BIGINTout参数值 public class MyDao { private final JdbcTemplate theTemplate;; /

我已经看到了许多从
simpleJdbcCall.executeFunction
获取单个原语结果的示例。我需要知道如何访问一组结果<代码>执行返回一个
映射
。您必须向
executeFunction
提供
SqlOutParameter
,并告诉它要返回的类型。我将返回映射到MyCustomClass.class,它返回null。我知道函数将返回3
BIGINT
out参数值

public class MyDao {
    private final JdbcTemplate theTemplate;;

    //@Autowired ctor

    public long createCategory(final CategoryEntity category) {
        final SimpleJdbcCall jdbcCall = getJdbcCall();

        return mapResult(jdbcCall.executeFunction(MyResultEntity.class, fromEntity(category)));
    }

    private long mapResult(MyResultEntity result) {
        return result.getOut_id();//FAIL
    }

    private SqlParameterSource fromEntity(final MyEntity category) {
        Map<String,Object> params = new HashMap<>();

        params.put("in_name", category.getName());
        params.put("in_description", category.getDescription());

        SqlParameterSource result = new MapSqlParameterSource(params);

        return result;
    }

    private SimpleJdbcCall getJdbcCall() {
        //I need the value returned by "out_id"
        SimpleJdbcCall jdbcCall = new SimpleJdbcCall(theTemplate)
                .withSchemaName("mySchema")
                .withFunctionName("my_function")
                .declareParameters(
                        new SqlOutParameter("out_id", Types.BIGINT),
                        new SqlOutParameter("out_2", Types.BIGINT),
                        new SqlOutParameter("out_3", Types.BIGINT)
                );

                return jdbcCall;
    }
}
公共类MyDao{
私有最终JdbcTemplate模板;;
//@自动接线的整流器
公共长类别(最终类别实体类别){
最后一个SimpleJdbcCall jdbcCall=getJdbcCall();
返回mapResult(jdbcCall.executeFunction(MyResultEntity.class,fromEntity(category));
}
私有长映射结果(MyResultEntity结果){
返回结果。getOut_id();//失败
}
私有SqlParameterSource fromEntity(最终MyEntity类别){
Map params=新的HashMap();
参数put(“in_name”,category.getName());
参数put(“in_description”,category.getDescription());
SqlParameterSource结果=新映射SqlParameterSource(参数);
返回结果;
}
私有SimpleJdbcCall getjdbcall(){
//我需要“out\u id”返回的值
SimpleJdbcCall=newSimpleJDBCall(模板)
.Wissechemaname(“mySchema”)
.withFunctionName(“我的函数”)
.申报参数(
新的SQLOutpParameter(“out_id”,Types.BIGINT),
新的SqlOutParameter(“out_2”,Types.BIGINT),
新的SQLOutpParameter(“out_3”,Types.BIGINT)
);
返回jdbcCall;
}
}

我发现您也可以使用
execute
调用函数。然后只需使用
Map
即可获得结果:

public long createCategory(final MyEntity category) {
    final SimpleJdbcCall jdbcCall = getJdbcCall();

    Map<String, Object> results = jdbcCall.execute(fromEntity(category));
    return (long) results.get("out_id");
}
public long createCategory(最终MyEntity类别){
最后一个SimpleJdbcCall jdbcCall=getJdbcCall();
Map results=jdbcCall.execute(fromtentity(category));
返回(长)结果。获取(“out_id”);
}