<select id="searchPage" resultMap="SearchPageResult">
select
<include refid="Base_Column_List"></include>
from T_USER
<where>DELETE_FLAG = 0
<if test="name != null and name != ''">
USERNAME like concat(#{name},'%')
</if>
</where>
</select>
<resultMap id="SearchPageResult" type="com.hj.hotel.entity.User" extends="BaseResultMap">
<collection property="roleList" column="{userId=ID}" javaType="java.util.List" select="com.hj.hotel.mapper.RoleMapper.selectByUserId">
</collection>
</resultMap>
<select id="selectByUserId" resultMap="SearchPageRoleResult">
select TR.ID TR_ID, TR.PID TR_PID, TR.CODE TR_CODE, TR.RULES TR_RULES, TR.NAME TR_NAME
from T_USER_ROLE TUR
LEFT JOIN T_ROLE TR on TUR.ROLE_ID = TR.id and TR.DELETE_FLAG = 0
<where>
TUR.USER_ID = #{userId}
</where>
</select>
<select id="searchPage" resultMap="SearchPageResult">
select TU.*, TR.ID TR_ID, TR.PID TR_PID, TR.CODE TR_CODE, TR.RULES TR_RULES, TR.NAME TR_NAME
from T_USER TU
left join T_USER_ROLE TUR on TU.ID = TUR.USER_ID
LEFT JOIN T_ROLE TR on TUR.ROLE_ID = TR.id and TR.DELETE_FLAG = 0
<where>TU.DELETE_FLAG = 0
<if test="name != null and name != ''">
TU.USERNAME like concat(#{name},'%')
</if>
</where>
</select>
<resultMap id="SearchPageResult" type="com.hj.hotel.entity.User" extends="BaseResultMap">
<collection property="roleList" ofType="com.hj.hotel.entity.Role">
<result column="TR_ID" property="id"/>
<result column="TR_PID" property="pid"/>
<result column="TR_CODE" property="code"/>
<result column="TR_RULES" property="rules"/>
<result column="TR_NAME" property="name"/>
</collection>
</resultMap>
用方式一时:IPage是基于主表做的分页
用方式二时:IPage是基于主表做的分页
用方式一时:IPage是基于主表做的分页,子表如果没有数据,主表依然存在
用方式二时:IPage是基于数据库返回的结果集去重分的页