mybatis collection应用实例

  • Post author:
  • Post category:其他
<resultMap id="BaseResultMap" type="com.gdkj.tmu_xg.pojo.SysPurview" >
    <result column="ROLEID" property="rid"></result>
    <result column="PURVIEW" property="id"></result>
    <result column="NAME" property="name"></result>
    <result column="CHECKED" property="checked"></result>
    <collection property="children" select="findChildMenu" column="{id=PURVIEW, rid = ROLEID}"/>
  </resultMap>

  <resultMap id="CheckedResultMap" type="com.gdkj.tmu_xg.pojo.SysPurview" >
    <result column="ROLEID" property="rid"></result>
    <result column="PURVIEW" property="id"></result>
    <result column="NAME" property="name"></result>
    <result column="URL" property="url"></result>
    <result column="CHECKED" property="checked"></result>
    <collection property="children" select="findCheckedChildMenu" column="{id=PURVIEW, rid = ROLEID}"/>
  </resultMap>
<select id="findChildMenu" resultMap="BaseResultMap">
    select 
    t.roleid, t.purview, t.checked, t.name
    from SYS_ROLE_PURVIEW t, syspurview s
    where t.purview = s.id and s.parent_id = #{id} and t.roleid = #{rid}
  </select>

<select id="findCheckedChildMenu" resultMap="CheckedResultMap">
    select
    t.roleid, t.purview, t.checked, t.name, s.url
    from SYS_ROLE_PURVIEW t, syspurview s
    where t.checked = 'true' and t.purview = s.id and s.parent_id = #{id} and t.roleid = #{rid}
  </select>

 


版权声明:本文为anjingjingg原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。