SpringBoot2.0集成分页插件pagehelper-spring-boot-starter
2023-09-27 14:21:10 时间
参考SpringBoot2.0集成分页插件pagehelper-spring-boot-starter
1. 添加pom
依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.13</version>
</dependency>
2. 添加配置
application.yml
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
application.prperties
# 添加分页配置信息
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql
pagehelper.page-size-zero=true
3. 在service中添加如下代码
// 开启分页插件,放在查询语句上面 帮助生成分页语句
PageHelper.startPage(page, size);
List<Attachment> attachments = attachmentMapper.getAllAttachments();
// 封装分页之后的数据 返回给客户端展示 PageInfo做了一些封装 作为一个类
PageInfo<Attachment> pageAttachments = new PageInfo<>(attachments);
return pageAttachments;
4. 控制器代码
@GetMapping("/attachment")
public ApiResponse getAllAttachmentsGroup(@RequestParam("page") Integer page, @RequestParam("size") Integer size) {
return attachmentService.getAllAttachments(page, size);
}
5. 返回数据
{
"code": 200,
"message": "success",
"timestamp": "2020-05-27T09:54:54.784+08:00",
"data": {
"total": 6,
"list": [
{
"id": 1,
"title": "来源组3",
"format": "doc",
"url": "/opt/data/aa4.doc",
"articleId": 1,
"size": 200,
"filename": "aa4.doc",
"filenameOrigin": "abc4.doc"
},
{
"id": 2,
"title": "来源组3",
"format": "doc",
"url": "/opt/data/aa5.doc",
"articleId": 1,
"size": 200,
"filename": "aa4.doc",
"filenameOrigin": "abc4.doc"
}
],
"pageNum": 1,
"pageSize": 2,
"size": 2,
"startRow": 1,
"endRow": 2,
"pages": 3,
"prePage": 0,
"nextPage": 2,
"isFirstPage": true,
"isLastPage": false,
"hasPreviousPage": false,
"hasNextPage": true,
"navigatePages": 8,
"navigatepageNums": [
1,
2,
3
],
"navigateFirstPage": 1,
"navigateLastPage": 3
}
}
相关文章
- spring boot mysql和mybatis
- Spring Boot 学习(3)
- 推荐 2 个 Spring Boot 的工作流项目
- Spring Boot 数据访问集成 MyBatis 与事物配置
- Spring Boot 集成JUnit5进行测试 Error creating bean with name 'serverEndpointExporter' defined in class path resource
- 为什么说 Java 程序员到了必须掌握 Spring Boot 的时候?
- Spring Boot 三大开发工具,你都用过几个?
- Spring Boot 集成 Apollo 配置中心,真香、真强大!
- Spring Boot 集成 WebSocket,轻松实现信息推送!
- Spring Boot Redis 实现分布式锁,真香!!
- Spring Boot 怎么打一个可执行 Jar 包?
- Spring Boot 集成 Swagger,生成接口文档就这么简单!
- Spring Boot 集成 Mybatis 实现双数据源
- Spring boot之hello word
- 集成maven和Spring boot的profile 专题
- 一篇文章学会spring boot(包括jms和hessian的集成)
- UReport2报表引擎:Spring Boot 集成 UReport2 报表引擎(一)
- Spring boot集成Swagger,并配置多个扫描路径
- Spring Boot 集成日志logback + 控制台打印SQL
- 详解Spring Boot配置文件之多环境配置
- 集成 Spring Boot 常用组件的后台快速开发框架 spring-boot-plus 国
- spring boot 集成Druid
- 细品 Spring Boot+Thymeleaf,还有这么多好玩的细节!
- 初识在Spring Boot中使用JPA
- spring boot druid动态多数据源监控集成
- Spring Boot中注入配置文件application.properties中的list 对象参数
- SpringBoot2.x系列教程(六十一)Spring Boot集成FastDFS实现文件上传
- SpringBoot2.x系列教程(四十八)Spring Boot集成JDBCTemplate