Mybatis 一对多分页数据条数不正确处理方式

今天在进行一对多的left join处理的时候发现分页的数据量不正确,后来把打印的sql去数据库执行,查询出来的确实是10条 1在xml里进行更改collect

今天在进行一对多的left join处理的时候发现分页的数据量不正确,后来把打印的sql去数据库执行,查询出来的确实是10条
1在xml里进行更改collection的映射

<resultMap id="userMap" type="com.abc.entity.SysUser"><id property="uid" column="uid"/><result property="uname" column="uname"/><result property="nick" column="nick"/><result property="pwd" column="pwd"/><result property="salt" column="salt"/><result property="lock" column="lock"/><result property="created" column="created" jdbcType="TIMESTAMP"/><result property="updated" column="updated" jdbcType="TIMESTAMP"/></resultMap><!-- 一对多:user、role --><resultMap id="userIncludeRolesMap" extends="userMap" type="com.abc.entity.SysUser"><collection property="roleList" column="uid"  select="QueryUserRoles"></collection></resultMap>

2.关联查询

 <select id="QueryUserRoles" resultType="com.abc.entity.SysRole">selectr.rid as rid,r.rname as rname,r.rdesc as rdesc,r.rval as rval,r.created as created,r.updated as updatedfrom  sys_user_role urleft join sys_role r on ur.role_id = r.ridwhere ur.user_id= #{uid}</select><select id="selectUserIncludeRoles" resultMap="userIncludeRolesMap">selectu.*from sys_user u<where><if test="uname != null and uname != ''">u.`uname` like concat('%',#{uname},'%')</if></where>order by u.uid</select>

主要就是把collection的映射数据拿一个子查询去映射,column就是从表要关联主表的那个字段

另:分页插件使用

Page page = PageHelper.startPage(xx,xx);
// todo:your query
PageInfo pageInfo = new PageInfo<>(page);