mybatis怎么接收oracle存储过程的结果

其实无论是返回以下哪种类型,其实都是键值对对的形式
普通类型
oracle(即存储过程)
create or replace procedure testReturnResult(returnResult out varchar2)
as
begin
   returnResult :='返回结果';
end ;
java
service:
Map<String,Object> mm=new HashMap<String,Object>();
this.j1SchedulingDao.testReturnResult(mm);
System.out.println("returnResult:"+mm.get("returnResult"));

dao:
public void testReturnResult(Map mm) throws SQLException;
mybatis
<select id="testReturnResult" parameterType="java.util.Map" statementType="CALLABLE">
{call testReturnResult(#{returnResult, mode=OUT, jdbcType=VARCHAR})}
</select>

游标类型
oracle(即存储过程)
create or replace procedure testReturnList(returnList out sys_refcursor)
as
begin
   open returnList for select *  from T_J1_SCHEDULING;
end ;
java
service:
Map<String,Object> mmap=new HashMap<String,Object>();
this.j1SchedulingDao.testReturnList(mmap);
List<Map<String,Object>> returnList = (List<Map<String, Object>>) mmap.get("returnList");

dao:
public void testReturnList(Map mm) throws SQLException;
mybatis
<select id="testReturnList" parameterType="java.util.Map" statementType="CALLABLE">/*resultMap=BaseResultMap*/
{call testReturnList(#{returnList, mode=OUT,jdbcType=CURSOR,resultMap=com.wonders.yyzl.dao.J1SchedulingDao.BaseResultMap})}
</select>

踩过的坑
  • The JDBC Type must be specified for output parameter. Parameter: returnResult 必须指定jdbcType
  • Parameters of type java.sql.ResultSet require a resultmap. 如果返回值是游标类型 必须指定resultmap
  • BaseResultMap is ambiguous in Result Maps collection (try using the full name including the namespace, or rename one of the entries) 需要指定包,指向对应的dao包 也就是当前的namespace.resultMap的id就可以了
[写博客只为记录,如有不对,还请各位大佬指出]
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值