简体   繁体   English

mybatis spring ref 游标映射

[英]mybatis spring ref cursor mapping

I am using mybatis-spring and trying to map a ref cursor from oracle.我正在使用 mybatis-spring 并尝试从 oracle 映射一个引用游标。 The result is coming back as null.结果返回为空。 Any ideas please?请问有什么想法吗?

<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: SP:

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

Map:地图:

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

DAO:道:

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

Usage:用法:

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

Many thanks,非常感谢,

OK, from the java side you need to use a map.好的,从java方面你需要使用地图。

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

The interface can now return void.该接口现在可以返回 void。 Then call the interface, like myDAO.check(myMap);然后调用接口,比如 myDAO.check(myMap);

The after call myMap.get("myVO"), and you will get back a List.之后调用 myMap.get("myVO"),你会得到一个 List。

I'm just clarifying the answer provided in the above post.我只是澄清上面帖子中提供的答案。

You need to define the map same as bean class members, this is to make sure the refcursor columns gets auto mapped to the properties in map and the list of bean objects.您需要定义与 bean 类成员相同的映射,这是为了确保 refcursor 列自动映射到映射中的属性和 bean 对象列表。

Mapper.xml映射器.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 should look like below: DAO 应如下所示:

public void check(Map response);

As the response and request are included in a map there won't be any return type specified in the DAO.由于响应和请求包含在映射中,因此 DAO 中不会指定任何返回类型。 Also the response data is tied to the Bean objects list.此外,响应数据与 Bean 对象列表相关联。

Usage:用法:

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....
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM