MyBatis注释调用存储过程并获取Params [英] MyBatis annotations to call Stored Procedure and get Out Params

查看:371
本文介绍了MyBatis注释调用存储过程并获取Params的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MyBAtis-3和MyBAtis-Spring。
当我尝试使用MyBatis注释调用一个返回多个params的存储过程时。我没有得到任何东西,我可以看到输入参数传递给日志中的SP,并且它在那里挂起,没有任何进度也没有抛出异常。

I am using MyBAtis-3 with MyBAtis-Spring. When i tried to call a stored procedure that returns more than one out params using MyBatis annotations. I don't get anything, I can see that the input parameter is passed to the SP in the logs and it hangs in there with no progress nor exception thrown.

PFB我试图从MyBAtis访问的Oracle存储过程,

PFB the Oracle Stored Procedure which i am trying to access from MyBAtis,

create or replace PROCEDURE C2C.GET_DATA
(
  "IN_PARAM1" IN NUMBER,
   "OUT_PARAM2" OUT SAMPLETABLE.COL2%TYPE,
   "OUT_PARAM3" OUT SAMPLETABLE.COL3%TYPE,
   "OUT_PARAM4" OUT SAMPLETABLE.COL4%TYPE
  )  AS

  BEGIN
    SELECT PARAM2,PARAM3,PARAM4 INTO 
    OUT_PARAM2,OUT_PARAM3,OUT_PARAM4
    FROM C2C.SAMPLETABLE WHERE PARAM1=IN_PARAM1 ;  

  END C2C.GET_DATA;

PFB映射器接口方法,

PFB the mapper interface method,

@Select(value= "{ CALL  C2C.GET_DATA( #{param1, mode=IN, jdbcType=INTEGER},#{param2, mode=OUT, jdbcType=VARCHAR},#{param3, mode=OUT, jdbcType=INTEGER},#{param4, mode=OUT, jdbcType=INTEGER})}")
@Options(statementType = StatementType.CALLABLE)
public void getData(Test test);

Test对象包含在Stored Procedure Call语句中作为输入传递的参数。

The Test object contains the parameters passed as input in the Stored Procedure Call statement.

当我执行此操作时,它会在这里被绞死,

When i execute this, it gets hanged over here,

main Slf4jImpl 
==>  Preparing: { CALL C2C.GET_DATA(?,?,?,?)} 

main Slf4jImpl 
==> Parameters: 60(Integer)


推荐答案

令人惊讶的是,如果我使用@插入注释它按预期工作。
调用存储过程时有些奇怪的行为。如果除此之外还有其他任何人有一个很好的解决方案,请告诉我。

Surprisingly if i use @Insert annotation it is working as expected. Some weird behavior while calling Stored Procedures. Let me know if any one else has a good solution other than this.

这篇关于MyBatis注释调用存储过程并获取Params的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆