MyBatisPlus可以自动分页,但是有些复杂的SQL的时候where条件时多余的,那么可以采取自定义SQL
代码中这么写
//1 禁止自动的SQL查询
mpPage.setSearchCount(false);
Long total = baseMapper.adminSearchUserPageCount(condition);
//2.正常查询,此时不会自动Count
Page<SearchUserPageResult> result = baseMapper.adminSearchUserPage(mpPage, condition);
//3. 赋值total
result.setTotal(total);
然后有一个对应的Mapper接口
Long adminSearchUserPageCount(@Param("condition") PageCondition condition);
当然也会有对应XML
<select id="adminSearchUserPageCount" resultType="long">
SELECT COUNT(*)
FROM user_core c
xxx
</select>