从 java 调用 oracle 存储过程时,在 mybatis 映射器中映射多个参数

问题是这样的,我想从java调用一个存储过程,使用mybatis / ibatis,这个过程有多个OUT参数,7精确地,其中2个是数字,其他5个Varchars,加上一个IN数字参数


上下文中有一个巨大的限制,即没有模型,只有映射和列表,尽管我们可以在必要时在调用过程时例外。此外,解决方案必须在java中完成,没有使用xml。


我有一个springboot应用程序,有一个休息服务,它调用一个服务bean,它调用Mapper接口,该接口定义了对我正在尝试执行的过程的调用。


到目前为止,我已经尝试在映射器界面中将结果映射到对象,列表,映射,使用@Result尝试逐个字段映射到特定的结果类,但一切都失败了...mybatis似乎执行了该过程而没有错误,但不幸的是没有返回任何内容。


我正在发布我的最新状态,其中包括尝试将结果映射到自定义类,它似乎执行该过程,但返回null


//custom class

public class ProcClass {

    Integer p_tipo_cliente;

    Integer p_codigo_cliente;

    String p_nombre_cliente;

    String p_cuit_cliente;

    String p_cuit_rp;

    String p_razon_social_rp;

    String p_domicilio;


// plus constructor, getters and setters

}


//Service method 

public ProcClass callProcedure(String param){

        return asociadoMapper.callProcedure(

                Integer.getInteger(param),0,0,

                "",",","","","");

    }



//Mapper interface


@Repository

public interface AsociadoMapper extends Mapper {



    @Select(value = AsociadoQueries.getDocumentoAsociadoCall)

    @Options(statementType = StatementType.CALLABLE)

    @Results(value = {

            @org.apache.ibatis.annotations.Result

                    (property = "p_tipo_cliente", column = "p_tipo_cliente"),

            @org.apache.ibatis.annotations.Result

                    (property = "p_codigo_cliente", column = "p_codigo_cliente"),

            @org.apache.ibatis.annotations.Result

                    (property = "p_nombre_cliente", column = "p_nombre_cliente"),

            @org.apache.ibatis.annotations.Result

                    (property = "p_cuit_cliente", column = "p_cuit_cliente"),

            @org.apache.ibatis.annotations.Result

                    (property = "p_cuit_rp", column = "p_cuit_rp"),

            @org.apache.ibatis.annotations.Result

                    (property = "p_razon_social_rp", column = "p_razon_social_rp"),

            @org.apache.ibatis.annotations.Result

                    (property = "p_domicilio", column = "p_domicilio"),

    })



预期的结果很简单,要么返回列表,映射,要么返回包含过程返回的OUT参数值的自定义类,现在,我得到的只是空或空列表...


米脂
浏览 185回答 1
1回答

九州编程

我刚刚设法弄清楚了,我想我必须自己回答,以防万一它帮助别人......,事实证明,我最终设法通过只发送1个map作为参数来获取参数,并在服务方法中设置IN值...此外,映射器现在正在返回 void,这意味着 mybatis 正在动态地将所有额外的 out 参数添加到映射中。我还对调用语句进行了一些更改,也许那里也有错误?代码的结尾如下:&nbsp; &nbsp; //service call&nbsp; &nbsp; public Map<String, Object> callProcedure(String param){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Map<String, Object> map = new HashMap<String, Object>();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Integer privilegesCount = 0;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; map.put("p_id_grupo_familiar", Integer.valueOf(param));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; asociadoMapper.callProcedure(map);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return map;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; //mapper&nbsp; &nbsp; &nbsp; &nbsp; @Select(value = AsociadoQueries.getDocumentoAsociadoCall)&nbsp; &nbsp; &nbsp; &nbsp; @Options(statementType = StatementType.CALLABLE)&nbsp; &nbsp; &nbsp; &nbsp; void callProcedure(Map<String,Object> params);// Call statementpublic static final String getDocumentoAsociadoCall = "{ CALL consultas_generales.get_detalle_cliente_gf(" +&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "#{p_id_grupo_familiar,&nbsp; jdbcType=NUMERIC ,javaType=java.lang.Integer ,mode=IN}," +&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "#{p_tipo_cliente, jdbcType=NUMERIC,javaType=java.lang.Integer ,mode=OUT,},"+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "#{p_codigo_cliente,&nbsp; jdbcType=NUMERIC ,javaType=java.lang.Integer ,mode=OUT},"+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "#{p_nombre_cliente,&nbsp; jdbcType=VARCHAR ,javaType=java.lang.String ,mode=OUT},"+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "#{p_cuit_cliente,&nbsp; jdbcType=VARCHAR ,javaType=java.lang.String ,mode=OUT},"+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "#{p_cuit_rp,&nbsp; jdbcType=VARCHAR ,javaType=java.lang.String ,mode=OUT},"+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "#{p_razon_social_rp,&nbsp; jdbcType=VARCHAR ,javaType=java.lang.String ,mode=OUT},"+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "#{p_domicilio, jdbcType=VARCHAR ,javaType=java.lang.String ,mode=OUT}"+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ")}";
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java