Spring Boot(08)分页插件

第08篇:分页插件pagehelper

流程

  1. 依赖
  2. 配置
  3. 使用

1. 依赖

<dependency>
	<groupId>com.github.pagehelper</groupId>
	<artifactId>pagehelper-spring-boot-starter</artifactId>
	<version>1.3.0</version>
</dependency>

2. 配置

pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql

3. 使用

3.1 返回分页数据

说明:只查询分页数据,而分页相关信息没有

public List<Count> getAllCount(int pageNo, int pageSize) {
	PageHelper.startPage(pageNo, pageSize);
	return countMapper.getAllCount();
}

返回值:

[{
	"id": 1,
	"cnt": 11
},
{
	"id": 2,
	"cnt": 12
},
{
	"id": 3,
	"cnt": 13
},
{
	"id": 4,
	"cnt": 14
},
{
	"id": 5,
	"cnt": 15
},
{
	"id": 6,
	"cnt": 16
},
{
	"id": 7,
	"cnt": 17
},
{
	"id": 8,
	"cnt": 18
},
{
	"id": 9,
	"cnt": 19
},
{
	"id": 10,
	"cnt": 10
}]
3.2 返回分页数据和分页信息
// mapper接口
Page<Count> getAllCount();

// service接口
public PageInfo<Count> getAllCount(int pageNo, int pageSize) {
   PageHelper.startPage(pageNo, pageSize);
   PageInfo<Count> pageInfo = new PageInfo<>(countMapper.getAllCount());
   return pageInfo;
}

返回值:

{
	"total": 15,
	"list": [{
		"id": 1,
		"cnt": 11
	},
	{
		"id": 2,
		"cnt": 12
	},
	{
		"id": 3,
		"cnt": 13
	},
	{
		"id": 4,
		"cnt": 14
	},
	{
		"id": 5,
		"cnt": 15
	},
	{
		"id": 6,
		"cnt": 16
	},
	{
		"id": 7,
		"cnt": 17
	},
	{
		"id": 8,
		"cnt": 18
	},
	{
		"id": 9,
		"cnt": 19
	},
	{
		"id": 10,
		"cnt": 10
	}],
	"pageNum": 1,
	"pageSize": 10,
	"size": 10,
	"startRow": 1,
	"endRow": 10,
	"pages": 2,
	"prePage": 0,
	"nextPage": 2,
	"isFirstPage": true,
	"isLastPage": false,
	"hasPreviousPage": false,
	"hasNextPage": true,
	"navigatePages": 8,
	"navigatepageNums": [1,2],
	"navigateFirstPage": 1,
	"navigateLastPage": 2
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值