Spring Boot 整合 PageHelper
依赖导入
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
测试分页
public Map<String, Object> findAllUser() {
Map<String,Object> map = new HashMap<>();
PageHelper.startPage(1,5);
List<User> userList = userMapper.findAllUser();
PageInfo<User> pageInfo = new PageInfo<>(userList);
map.put("data",pageInfo);
return map;
}
结果
{
data: {
total: 20
list: [
0: {...}
1: {...}
2: {...}
3: {...}
4: {...}
]
pageNum: 1
pageSize: 5
size: 5
startRow: 1
endRow: 5
pages: 4
prePage: 0
nextPage: 2
isFirstPage: true
isLastPage: false
hasPreviousPage: false
hasNextPage: true
navigatePages: 8
navigatepageNums: [...]
navigateFirstPage: 1
navigateLastPage: 4
}
}