设置searchCount属性为false
示例
public Page<User> selectUserPage(Page<User> page, Integer state) {
// 不进行 count sql 优化,解决 MP 无法自动优化 SQL 问题
// page.setOptimizeCountSql(false);
// 不查询总记录数
// page.setSearchCount(false);
// 注意!! 分页 total 是经过插件自动 回写 到传入 page 对象
return page.setRecords(userMapper.selectUserList(page, state));
}
同理
/**
* 多表关联分页查询
*
* @param page 分页参数
* @param model 搜索条件
*/
@RequestMapping(value = "/list", method = RequestMethod.GET)
public ResponseObj<Page<PbFamily>> list(@ModelAttribute Page<PbFamily> page,
@ModelAttribute PbFamily model) {
// 不查询总记录数
page.setSearchCount(false);
// page.setOptimizeCountSql(false);
Page<PbFamily> pageList = service.list(page, new EntityWrapper<>(model));
return new ResponseObj<>(pageList, RetCode.SUCCESS);
}
}
分页查询返回总记录数的结果如下
{
"retCode": {
"status": "0000"
},
"data": {
"total": 1515,
"size": 10,
"pages": 152,
"current": 1,
"isAsc": true,
"records": [
{ },
{ },
{ }
]
}
}
分页查询不返回总记录数的结果如下
{
"retCode": {
"status": "0000"
},
"data": {
"total": 0,
"size": 10,
"pages": 0,
"current": 1,
"isAsc": true,
"records": [
{ },
{ },
{ }
]
}
}
网友评论