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。

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

  • 相关阅读:
    javascript 时间与时间戳的转换
    javascript 判断对象的内置类型
    javascript 动态脚本添加
    javascript select标签的操作
    javascript canvas画订单
    css 移动端图片等比显示处理
    FastDFS分布式文件系统
    欧拉回路--模板
    tarjan求双联通分量--POJ 1523 +P2860 [USACO06JAN]Redundant Paths G
    tarjan求割点和割边
  • 原文地址:https://www.cnblogs.com/GYoungBean/p/2814290.html
Copyright © 2011-2022 走看看