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<String, Object> params = new HashMap<String, Object>();
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<Map<String, Object>>());//傳入一個jdbc游標,用於接收返回參數
this. batisDao. getSearchList("call_Fsp_Plan_CheckPrj", params);

mybatis xml配置

<resultMap type ="java.util.HashMap" id= "cursorMap">
   <
!--配置返回游標中別名對應的resultMap --> <result column ="plan_code" property="plan_code" /> <result column ="plan_dept" property="plan_dept" /> <result column ="plan_amount" property="plan_amount" /> <result column ="exec_amount" property="exec_amount" /> <result column ="plan_name" property="plan_name" /> <result column ="dept_name" property="dept_name" /> </resultMap > <select id ="call_Fsp_Plan_CheckPrj" parameterType= "map" statementType="CALLABLE" > <!--注明statementType="CALLABLE"表示調用存儲過程--> {call Fsp_Plan_CheckPrj(#{grantNo, jdbcType=VARCHAR, mode=IN}, #{offOrgCode, jdbcType=INTEGER, mode=IN},                   #{v_cursor, mode=OUT, jdbcType=CURSOR, resultMap=cursorMap})} <!--傳入傳出參數要注明mode=IN/OUT 並要注明jdbcType(在網上可以查詢mybatis支持哪些jdbcType類型),返回參數要注明對應的resultMap--> </select >

最后,在jsp頁面只需遍歷 
params.put( "v_cursor", OracleTypes. CURSOR);中的v_cursor。本身就是一個可遍歷的list結果集

本文轉自:http://blog.csdn.net/a9529lty/article/details/24401423


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM