一、导入依赖
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.4.1</version>--> </dependency>
二、查询前后增加PageHelper和PageInfo
@Override public AjaxResult selectPageList(Integer currentPage, Integer pageSize) { //增加PageHelper PageHelper.startPage(currentPage,pageSize); List<SysDept> sysDepts = sysDeptMapper.selectPageList(); //增加PageInfo PageInfo<SysDept> info=new PageInfo<>(sysDepts); return AjaxResult.success(info); }
三、返回结果
调用接口
http://localhost:10200/admin/dept/slelectpage?currentPage=2&pageSize=1
{ "msg": "操作成功", "code": 200, "data": { "endRow": "2", "hasNextPage": true, "hasPreviousPage": true, "isFirstPage": false, "isLastPage": false, "list": [ { "createBy": "demoData", "createTime": "2021-07-03 09:15:57", "deptName": "demoData", "depth": "demoData", "id": "2", "leaderId": "demoData", "level": 1, "parentId": 2, "updateBy": "demoData", "updateTime": "2021-07-03 09:17:40" } ], "navigateFirstPage": 1, "navigateLastPage": 3, "navigatePages": 8, "navigatepageNums": [ 1, 2, 3 ], "nextPage": 3, "pageNum": 2, "pageSize": 1, "pages": 3, "prePage": 1, "size": 1, "startRow": "2", "total": "3" } }