引入pagehelper依赖后
需要排除Mybatis的依赖, 否则会启动报错
注:如果是多模块, 此依赖需要放入到父pom里,不然项目启动不了
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
<exclusions>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</exclusion>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</exclusion>
</exclusions>
</dependency>
yml里配置
pagehelper:
helper-dialect: mysql
reasonable: true
support-methods-arguments: true
page-size-zero: true
params: count=countSql
@GetMapping("/getAllIp")
public PageInfo<IpBean> getAllIp() throws IOException {
//分页
PageHelper.startPage(1 ,10);
List<IpBean> IpBeanList=null;
List<IpBean> ipBeanList = ipBeanService.list();
PageInfo<IpBean> pageInfo = new PageInfo(ipBeanList);
return pageInfo;
}
{
"pageNum": 1,
"pageSize": 10,
"size": 10,
"startRow": 1,
"endRow": 10,
"total": 200,
"pages": 20,
"list": [
{
"ipAddress": "61.145.49.125",
"ipPort": 9999,
"serverAddress": "广东江门",
"anonyType": "高匿",
"protocolType": "HTTPS"
},
.....已省略,共10条数据
],
"prePage": 0,
"nextPage": 2,
"isFirstPage": true,
"isLastPage": false,
"hasPreviousPage": false,
"hasNextPage": true,
"navigatePages": 8,
"navigatepageNums": [
1,
2,
3,
4,
5,
6,
7,
8
],
"navigateFirstPage": 1,
"navigateLastPage": 8,
"firstPage": 1,
"lastPage": 8
}