<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.shop.core.common.mapper.ClubAdminModuleMapper">
<resultMap id="BaseResultMap" type="com.shop.core.beans.ClubAdminModule">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="module_name" jdbcType="VARCHAR" property="moduleName" />
<result column="parent_id" jdbcType="INTEGER" property="parentId" />
<result column="url" jdbcType="VARCHAR" property="url" />
<result column="user_role" jdbcType="INTEGER" property="userRole" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="name" jdbcType="VARCHAR" property="name" />
</resultMap>
<resultMap id="ResultModuleMap" extends="BaseResultMap" type="com.shop.core.beans.ClubAdminModuleParam" >
<collection property="moduleList" column="id" select="com.shop.core.common.mapper.ClubAdminModuleMapper.selectByParentId"/>
<collection property="moduleJurList" column="id" select="com.shop.core.common.mapper.ClubAdminModuleJurMapper.selectByModuleId"/>
<collection property="role" column="user_role" select="com.shop.core.common.mapper.ClubAdminUserRoleMapper.selectByPrimaryKey"/>
<collection property="parentModuleName" column="parent_id" select="com.shop.core.common.mapper.ClubAdminModuleMapper.selectParentName"/>
</resultMap>
<select id="selectByParentId" resultMap="ResultModuleMap" parameterType="java.lang.Integer" >
select *
from club_admin_module
where parent_id = #{id,jdbcType=INTEGER} order by id
</select>
<select id="selectAll" parameterType="java.lang.Integer" resultMap="ResultModuleMap">
select *
from club_admin_module
where 1=1
<if test="roleId != null and roleId !='' ">
and user_role = #{roleId,jdbcType=INTEGER}
</if>
</select>
首先是,调用selectAll方法进入mapper.xml文件 返回ResultModuleMap 结果映射,ResultModuleMap包含 这条语句,这条语句查询又返回ResultModuleMap,一直这样递归调用,就分级查询子集的结果。
注意返回的对象要封装子集的结果集。List moduleList;
是不是很简单!