(七)SpringBoot使用PageHelper分页插件
二:添加PageHelper依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency>
三:添加PageHelper配置
在application.properties
中添加
logging.level.com.example.demo.dao=DEBUG
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql
pagehelper.page-size-zero=true
四:使用方法
UserInfoMapper.xml
<select id="selectAll" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from user_info
</select>
UserInfoMapper
List<UserInfo> selectAll();
UserInfoServiceImpl
@Override
public PageInfo<UserInfo> selectAll(Integer page, Integer size) {
//开启分页查询,写在查询语句上方
//每页的数量 pageSize;
//当前页的数量 size;
PageHelper.startPage(page, size);
List<UserInfo> userInfoList = userInfoMapper.selectAll();
PageInfo<UserInfo> pageInfo = new PageInfo<>(userInfoList);
return pageInfo;
}
UserInfoController
@ApiOperation(value = "查询用户", notes = "分页查询用户所有")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "当前页码",
dataType = "Integer", paramType = "query"),
@ApiImplicitParam(name = "size", value = "每页显示条数",
dataType = "Integer", paramType = "query")
})
@PostMapping("/selectAll")
public RetResult<PageInfo<UserInfo>> selectAll(@RequestParam(defaultValue = "0") Integer page,
@RequestParam(defaultValue = "0") Integer size) {
PageInfo<UserInfo> pageInfo = userInfoService.selectAll(page, size);
return RetResponse.makeOKRsp(pageInfo);
}
五:PageHelper中默认PageInfo的成员变量介绍
//当前页
private int pageNum;
//每页的数量
private int pageSize;
//当前页的数量
private int size;
//当前页面第一个元素在数据库中的行号
private int startRow;
//当前页面最后一个元素在数据库中的行号
private int endRow;
//总记录数
private long total;
//总页数
private int pages;
//结果集
private List<T> list;
//第一页
private int firstPage;
//前一页
private int prePage;
//是否为第一页
private boolean isFirstPage;
//是否为最后一页
private boolean isLastPage;
//是否有前一页
private boolean hasPreviousPage;
//是否有下一页
private boolean hasNextPage;
//导航页码数
private int navigatePages;
//所有导航页号
private int[] navigatepageNums;
六:功能测试
地址:http://192.168.1.104:8080/userInfo/selectAll
情况一:不传参数,默认为全查询
情况二:参数 page=2&size=1
(七)SpringBoot使用PageHelper分页插件的更多相关文章
- Springboot 使用PageHelper分页插件实现分页
一.pom文件中引入依赖 二.application.properties中配置以下内容(二选一方案) 第一种:pagehelper.helper-dialect=mysqlpagehelper.re ...
- SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页
SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页 **SpringBoot+Mybatis使用Pagehelper分页插件自动分页,非常好用,不用在自己去计算和组装了. ...
- Springboot 系列(十二)使用 Mybatis 集成 pagehelper 分页插件和 mapper 插件
前言 在 Springboot 系列文章第十一篇里(使用 Mybatis(自动生成插件) 访问数据库),实验了 Springboot 结合 Mybatis 以及 Mybatis-generator 生 ...
- SpringBoot整合系列-PageHelper分页插件
原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9971043.html SpringBoot整合MyBatis分页插件PageHelper ...
- SpringBoot 使用 MyBatis 分页插件 PageHelper 进行分页查询
前言:本文档使用的是 SpringBoot,如果是 Spring 还需要在 MyBatis 配置 xml 中配置拦截器,并且 PageHelper 是针对 MyBatis 的,MyBatis 的集成不 ...
- SpringBoot入门篇--整合mybatis+generator自动生成代码+druid连接池+PageHelper分页插件
原文链接 我们这一篇博客讲的是如何整合Springboot和Mybatis框架,然后使用generator自动生成mapper,pojo等文件.然后再使用阿里巴巴提供的开源连接池druid,这个连接池 ...
- 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_3-5.PageHelper分页插件使用
笔记 5.PageHelper分页插件使用 简介:讲解开源组件,mybaits分页插件的使用 1.引入依赖 <!-- 分页插件依赖 --> ...
- springboot + mybatis配置分页插件
一:使用pagehelper配置分页插件 1:首先配置springboot +mybatis框架 参考:http://www.cnblogs.com/liyafei/p/7911549.html 2 ...
- PageHelper分页插件的使用
大家好!今天写ssm项目实现分页的时候用到pageHelper分页插件,在使用过程中出现了一些错误,因此写篇随笔记录下整个过程 1.背景:在项目的开发的过程中,为了实现所有的功能. 2.目标:实现分页 ...
随机推荐
- INAPP登陆调用的FB接口
public function login_get (){ $this->load->helper ( 'auth' ); $redirectUrl = $this->input-& ...
- JQUERY多选框,单选框,检查选中的值
var str=""; $(":checkbox:checked").each(function(){ if($(this).attr("checke ...
- ios自动生成对象类,提高开发速率
#import "autoGenerationFileUtility.h" @implementation autoGenerationFileUtility - (void)cr ...
- Android WIFI模块分析
一:什么是WIFI WIFI是一种无线连接技术.可用于手机.电脑.PDA等终端. WIFI技术产生的目的是改善基于IEEE802.11标准的无线网络产品之间的互通性,也就是说WIFI是基于802.11 ...
- 《STL源代码剖析》---stl_deque.h阅读笔记(2)
看完,<STL源代码剖析>---stl_deque.h阅读笔记(1)后.再看代码: G++ 2.91.57,cygnus\cygwin-b20\include\g++\stl_deque. ...
- ExtJs4.2 开发问题总结
1. 在开发treegrid中,store属性autoLoad:false没有作用,还会默认自动加载.目前解决办法在control下监听treegrid的afterrender,当加载完后,再调一次s ...
- C语言操作SQLite数据库
SQLite头文件和源文件下载地址http://www.sqlite.org/download.html 以下是示例代码 #include <stdio.h> #include " ...
- C++虚复制构造函数,设置Clone()方法返回基类指针,并设置为虚函数
构造函数不能是虚函数.但有时候确实需要能传递一个指向基类对象的指针,并且有已创建的派生类对象的拷贝.通常在类内部创建一个Clone()方法,并设置为虚函数. //Listing 12.11 Virtu ...
- 从小姐姐博客那里看到的流光文字(CSS3 animate)
对于流光文字,大家并不陌生,毕竟我们都经历过非主流的时代.你们卟懂绯紸流!色彩缤纷的QQ空间...... 还记得那些炫酷的签名档,或者那些炫酷的动态头像.不过大家对于流光文字的印象还是图片.那么在网页 ...
- HDU 6114 Chess 【组合数】(2017"百度之星"程序设计大赛 - 初赛(B))
Chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...