1. 存储过程示例:

  2. create or replace procedure Fsp_Plan_CheckPrj(v_grantno  varchar2, v_deptcode number,  v_cursor out sys_refcursor) is

  3. ………………

  4. ---返回统计结果

  5. open v_Cursor for

  6. select s.plan_code,

  7. s.plan_dept,

  8. s.plan_amount,

  9. s.exec_amount,

  10. p.cname as plan_name,

  11. d.cname as dept_name

  12. from Snap_plan_checkprj s

  13. left join v_plan p

  14. on s.plan_code = p.plan_code

  15. left join org_office d

  16. on s.plan_dept = d.off_org_code

  17. group by s.plan_code,

  18. s.plan_dept,

  19. s.plan_amount,

  20. s.exec_amount,

  21. p.cname,

  22. d.cname;

  23. end ;

  24. end Fsp_Plan_CheckPrj;



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

java层代码


[java] view plain copy mybatis 调用存储过程 返回游标 实例_mybatis 调用存储过程 返回游标 mybatis 调用存储过程 返回游标 实例_mybatis 调用存储过程 返回游标 _02

  1. Map<String, Object> params = new HashMap<String, Object>();

  2. GrantSetting gs = this . grantSettingDao.get(grantCode);

  3. params.put( "grantNo" , StringUtils. substring(gs.getGrantNo(), 0 , 2 ));

  4. params.put( "offOrgCode" , SecurityUtils.getPersonOffOrgCode());

  5. params.put( "v_cursor" , new ArrayList<Map<String, Object>>()); //传入一个jdbc游标,用于接收返回参数

  6. this . batisDao. getSearchList( "call_Fsp_Plan_CheckPrj" , params);


mybatis xml配置

[html] view plain copy mybatis 调用存储过程 返回游标 实例_mybatis 调用存储过程 返回游标 mybatis 调用存储过程 返回游标 实例_mybatis 调用存储过程 返回游标 _02

  1. < resultMap type = "java.util.HashMap" id = "cursorMap" > < !--配置返回游标中别名对应的resultMap -- >

  2. < result column = "plan_code" property = "plan_code" />

  3. < result column = "plan_dept" property = "plan_dept" />

  4. < result column = "plan_amount" property = "plan_amount" />

  5. < result column = "exec_amount" property = "exec_amount" />

  6. < result column = "plan_name" property = "plan_name" />

  7. < result column = "dept_name" property = "dept_name" />

  8. </ resultMap >

  9. < select id = "call_Fsp_Plan_CheckPrj" parameterType = "map" statementType = "CALLABLE" >

  10. <!--注明statementType="CALLABLE"表示调用存储过程-->

  11. {call Fsp_Plan_CheckPrj(#{grantNo, jdbcType = VARCHAR , mode = IN },

  12. #{offOrgCode, jdbcType = INTEGER , mode = IN },

  13. #{v_cursor, mode = OUT , jdbcType = CURSOR , resultMap = cursorMap })}

  14. <!--传入传出参数要注明mode=IN/OUT 并要注明jdbcType(在网上可以查询mybatis支持哪些jdbcType类型),返回参数要注明对应的resultMap-->

  15. </ select >


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