【问题标题】:mybatis spring ref cursor mappingmybatis spring ref 游标映射
【发布时间】:2015-06-19 18:48:13
【问题描述】:

我正在使用 mybatis-spring 并尝试从 oracle 映射一个引用光标。结果返回为空。请问有什么想法吗?

<select id="check" parameterType="myVO" 
        resultMap="VOResultMap" statementType="CALLABLE" resultType="object">
{ call MYPKG.proc_check(
        #{myVO.id, javaType=String, jdbcType=VARCHAR,mode=IN},
        #{myVO, mode=OUT, javaType=ResultSet, jdbcType=CURSOR, resultMap=VOResultMap}
)}  

SP:

PROCEDURE proc_check (        
    p_id IN VARCHAR2, po_outCursor OUT SYS_REFCURSOR)
IS
BEGIN        
        OPEN po_outCursor FOR 
            SELECT * FROM MYTABLE; 
END;

地图:

<resultMap id="VOResultMap" type="myVO">
    <result property="action" column="ACTION" />
    <result property="id" column="ID" />
    <result property="name" column="NAME" />
</resultMap>

道:

public MyVO check(@Param("VO") MyVO myVO);

用法:

MyVO myVO = new MyVO(id);
MyVO obj = myDAO.check(myVO);
// obj is null !!

非常感谢,

【问题讨论】:

    标签: java spring oracle stored-procedures mybatis


    【解决方案1】:

    好的,从java端你需要使用地图。

    在xml中设置parameterType="java.util.Map" 在 Java 中放入“in”参数,即 map.put("id", identifier);

    接口现在可以返回 void。 然后调用接口,比如myDAO.check(myMap);

    之后调用myMap.get("myVO"),你会得到一个List。

    【讨论】:

      【解决方案2】:

      我只是澄清上述帖子中提供的答案。

      您需要定义与 bean 类成员相同的映射,这是为了确保 refcursor 列自动映射到映射中的属性和 bean 对象列表。

      映射器.xml

          <select id="check"  
                  parameterType="java.util.Map" 
                  resultMap="VOResultMap" statementType="CALLABLE">
              { call MYPKG.proc_check(
                  #{id, javaType=String, jdbcType=VARCHAR,mode=IN},
                  #{myVO, mode=OUT, javaType=ResultSet, jdbcType=CURSOR, resultMap=VOResultMap}
              )} 
              </select>
      
          <!-- In the out parameter you need to mention the DTO as it's signature is same as sysrefcursor. 
          There is no difference between sysrefcursor and refcursor except for the creation of the type of refcursor in the proc body or in package -->
          
          <resultMap id="VOResultMap" type="myVO">
                  <result property="action" column="ACTION" />
                  <result property="id" column="ID" />
                  <result property="name" column="NAME" />
          </resultMap>
      

      DAO 应该如下所示:

      public void check(Map response);
      

      由于响应和请求都包含在映射中,因此不会在 DAO 中指定任何返回类型。响应数据也与 Bean 对象列表相关联。

      用法:

      Map responseMap = new HashMap();
      responseMap.put("id","identifier");
      myDAO.check(responseMap);
      List<MyVO> responseList = (List<MyVO>) responseMap.get("myVO");
      for (MyVO myVO : responseList) {
          your logic....
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-01
        • 2014-10-11
        相关资源
        最近更新 更多