zoukankan      html  css  js  c++  java
  • Ibatis中返回一对多结果集的解决方法

    之前遇到过类似的问题,今天记录下。版本比较低的文档中(具体几的文档忘记了..)记得有介绍在<resultMap>下<result>标签使用 select属性。例如:

    <resultMap class="xxx" id="xx">
        <result property="xxx" column="xxx" select="xxSQL" />
    </resultMap>

    但是这种解决方法不是很好。如果在Bean中的属性有集合类,可以使用以下的方式

    <sqlMap namespace="xxxSQL">
        <typeAlias alias="sysUser"
            type="xx.SysUser" />
        <typeAlias alias="userCommunity"
            type="xx.UserCommunity" />
        
        <resultMap class="userCommunity" id="comm" >
            <result property="communityCode" column="COMMUNITY_CODE"/>
            <result property="communityName" column="MC" />
        </resultMap>
        <resultMap class="sysUser" id="sysCom" groupBy="loginId">
            <result property="loginId" column="LOGIN_ID"/>
            <result property="userCommunityList" resultMap="xxxSQL.comm"/>
        </resultMap>
        
        <select id="getSysUserRole" resultMap="sysCom">
            SELECT S.LOGIN_ID, U.COMMUNITY_CODE, C.MC
             FROM SYS_USER S, USER_COMMUNITY U, ccc C
            WHERE S.LOGIN_ID = U.POLICE_NO
            AND u.community_code = c.dm
            ORDER BY S.LOGIN_ID 
        </select>
    </sqlMap>    

    需要注意的是,在id='sysCom'的<result property="userCommunityList" resultMap="xxxSQL.comm" />中一定要指定SQL的namespace。

    -------------------------------------分割线----------未完待补充---------------------

  • 相关阅读:
    MyBatis学习(一)
    ORM框架
    Java 核心技术点之注解
    git 分支 合并
    TensorFlow——零碎语法知识点
    TensorFlow——深入MNIST
    tensorflow——MNIST机器学习入门
    TensorFlow——小练习:feed
    TensorFlow——小练习:counter
    TensorFlow——交互式使用会话:InteractiveSession类
  • 原文地址:https://www.cnblogs.com/GYoungBean/p/2814290.html
Copyright © 2011-2022 走看看