使用mybatis-plus-join的一对多查询,不能使用分页插件,如下代码:
MPJLambdaWrapper<TableA> wrapper = new MPJLambdaWrapper<TableA>()
.selectAll(TableA.class)
.selectCollection(TableB.class, TableADTO::getBList, b -> b
.collection(TableC.class, TableBDTO::getCcList, c -> c
.collection(TableD.class, TableCDTO::getDList, d -> d
.collection(TableE.class, TableDDTO::getEList))))
.leftJoin(TableB.class, TableB::getAid, TableA::getId)
.leftJoin(TableC.class, TableC::getBid, TableB::getId)
.leftJoin(TableD.class, TableD::getCid, TableC::getId)
.leftJoin(TableE.class, TableE::getDid, TableD::getId);
List<TableADTO> dtos = tableAMapper.selectJoinList(TableADTO.class, wrapper);
等效与
<resultMap id="xxxxxxxx" type="com.github.yulichang.join.dto.UserDTO">
<result property="id" column="id"/>
<result property="name" column="name"/>
<collection property="addressList" javaType="java.util.List"
ofType="com.github.yulichang.join.entity.UserAddressDO">
<id property="id" column="mpj_id"/>
<result property="address" column="address"/>
<result property="userId" column="user_id"/>
</collection>
</resultMap>
mybaytis会在分页后再处理结果集进行collection 处理,会导致结果集数量变少
如 关联查询数据,分页查询后得到20条,但是其中一条主表数据对应两条数据,collection处理后,会变成19条数据,就导致Page.size值为20,而Page.records数量为19