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。

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

  • 相关阅读:
    GNU make manual 翻译(九十九)
    GNU make manual 翻译( 九十五)
    Shell的 for 循环小例子
    makefile中对目录遍历的小例子
    GNU make manual 翻译(九十三)
    GNU make manual 翻译( 一百)
    GNU make manual 翻译( 九十七)
    GNU make manual 翻译( 九十八)
    mapserver4.8.3 的readme.win32的中文翻译文件
    遥控器编程
  • 原文地址:https://www.cnblogs.com/GYoungBean/p/2814290.html
Copyright © 2011-2022 走看看