mybatis 调用存储过程 返回游标 实例

存储过程示例: 
create or replace procedure Fsp_Plan_CheckPrj(v_grantno  varchar2, v_deptcode number,  v_cursor   out sys_refcursor) is 
……………… 
    ---返回统计结果 
    open v_Cursor for 
      select s.plan_code, 
             s.plan_dept, 
             s.plan_amount, 
             s.exec_amount, 
             p.cname       as plan_name, 
             d.cname       as dept_name 
        from Snap_plan_checkprj s 
        left join v_plan p 
          on s.plan_code = p.plan_code 
        left join org_office d 
          on s.plan_dept = d.off_org_code 
       group by s.plan_code, 
                s.plan_dept, 
                s.plan_amount, 
                s.exec_amount, 
                p.cname, 
                d.cname; 
  end; 
end Fsp_Plan_CheckPrj;  


mybatis:(mybatis doc api:  http://mybatis.github.io/mybatis-3/zh/sqlmap-xml.html#Result_Maps) 

java层代码

Map params = new HashMap();
GrantSetting gs = this. grantSettingDao.get(grantCode);
params.put( "grantNo", StringUtils. substring(gs.getGrantNo(), 0, 2));
params.put( "offOrgCode", SecurityUtils.getPersonOffOrgCode());

params.put("v_cursor", new ArrayList>());//传入一个jdbc游标,用于接收返回参数
this. batisDao. getSearchList("call_Fsp_Plan_CheckPrj", params);

mybatis xml配置 

<!--配置返回游标中别名对应的resultMap -->
     
     
     
     
     
     



最后,在jsp页面只需遍历 
params.put( "v_cursor", OracleTypes. CURSOR);中的v_cursor。本身就是一个可遍历的list结果集 

你可能感兴趣的:(iBatis)