• 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

  • 相关阅读:
    【超分辨率】—基于深度学习的图像超分辨率最新进展与趋势
    【超分辨率】—超分辨率补充问题
    随机采样一致算法RANSAC
    【相机篇】从到FlyCapture2到Spinnaker
    【超分辨率】—(ESRGAN)增强型超分辨率生成对抗网络-解读与实现
    AI佳作解读系列(六) - 生成对抗网络(GAN)综述精华
    AI佳作解读系列(五) - 目标检测二十年技术综述
    TroubleShooting经验总结
    读书笔记 - 《深度学习之美》(更新中...)
    深度学习中那些有趣的定理或理论
  • 原文地址:https://www.cnblogs.com/dreammyle/p/4548295.html
Copyright © 2020-2023  润新知