springboot mybatis pagehelper 分页问题

时间:2023-12-22 15:29:26

1:添加依赖

compile group: 'com.github.pagehelper', name: 'pagehelper-spring-boot-starter', version: '1.2.9'
注意:在spring-boot中一定要使用 pagehelper-spring-boot-starter而不是pagehelper,否则分页不起作用。

2:应用案例

@RequestMapping(
value = "/page",
method = RequestMethod.GET
)
public ResultVo getUserPages(@RequestParam Integer pageNum, @RequestParam Integer pageSize){
PageHelper.startPage(pageNum, pageSize);//一定要在userMapper.getUsers()之前执行
List<UserVo> list = userMapper.getUsers();
PageInfo<UserVo> pageInfo = new PageInfo<>(list,pageSize); return ResultUtil.dealPageResult(pageInfo, "用户分页信息");
}