二:添加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分页插件的更多相关文章

  1. Springboot 使用PageHelper分页插件实现分页

    一.pom文件中引入依赖 二.application.properties中配置以下内容(二选一方案) 第一种:pagehelper.helper-dialect=mysqlpagehelper.re ...

  2. SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页

    SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页 **SpringBoot+Mybatis使用Pagehelper分页插件自动分页,非常好用,不用在自己去计算和组装了. ...

  3. Springboot 系列(十二)使用 Mybatis 集成 pagehelper 分页插件和 mapper 插件

    前言 在 Springboot 系列文章第十一篇里(使用 Mybatis(自动生成插件) 访问数据库),实验了 Springboot 结合 Mybatis 以及 Mybatis-generator 生 ...

  4. SpringBoot整合系列-PageHelper分页插件

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9971043.html SpringBoot整合MyBatis分页插件PageHelper ...

  5. SpringBoot 使用 MyBatis 分页插件 PageHelper 进行分页查询

    前言:本文档使用的是 SpringBoot,如果是 Spring 还需要在 MyBatis 配置 xml 中配置拦截器,并且 PageHelper 是针对 MyBatis 的,MyBatis 的集成不 ...

  6. SpringBoot入门篇--整合mybatis+generator自动生成代码+druid连接池+PageHelper分页插件

    原文链接 我们这一篇博客讲的是如何整合Springboot和Mybatis框架,然后使用generator自动生成mapper,pojo等文件.然后再使用阿里巴巴提供的开源连接池druid,这个连接池 ...

  7. 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_3-5.PageHelper分页插件使用

    笔记 5.PageHelper分页插件使用     简介:讲解开源组件,mybaits分页插件的使用 1.引入依赖             <!-- 分页插件依赖 -->          ...

  8. springboot + mybatis配置分页插件

    一:使用pagehelper配置分页插件 1:首先配置springboot +mybatis框架  参考:http://www.cnblogs.com/liyafei/p/7911549.html 2 ...

  9. PageHelper分页插件的使用

    大家好!今天写ssm项目实现分页的时候用到pageHelper分页插件,在使用过程中出现了一些错误,因此写篇随笔记录下整个过程 1.背景:在项目的开发的过程中,为了实现所有的功能. 2.目标:实现分页 ...

随机推荐

  1. 使用session来存储用户的登录信息

    对存在cookie端数据进行加密处理,具体代码如下: <?php session_start(); //假设用户登录成功获得了以下用户数据 $userinfo = array( 'uid' =& ...

  2. Intel processor brand names-Xeon,Core,Pentium,Celeron----Quark

    http://en.wikipedia.org/wiki/Intel_Quark Intel Quark From Wikipedia, the free encyclopedia     Intel ...

  3. 【前端】怎样成长为一名优秀的前端project师---

    浅谈本人的经验.也算是与大家交流吧,本人眼下也是从事前端的工作,时间并不长,说的不好,请见谅. 首先,前端project师必须得掌握HTML.CSS和JavaScript. 仅仅懂当中一个或两个还不行 ...

  4. libusb 源码阅读

    libusb_init(NULL), 如果传入一个NULL, 则libusb 内部会有一个 usbi_default_context 变量在内部保存上下文. 这样以后调用 libusb 函数时可以不指 ...

  5. ubuntu git ssh不通

    xyh@ubuntu-64:~$ ssh -v git@danxinben.com                                                            ...

  6. java语句顺序有时非常重要

    我们学习java时,通常被告知,变量定义的顺序不重要,可是下面程序确在jdk 1.7上执行出错. public class FactoryImpl implements Serializable { ...

  7. 赵雅智_SimpleCursorAdapter

    项目步骤 声明listView控件并获取显示的视图 获取显示的数据 设置显示的adapter 注冊点击事件 详细案例 实现效果: watermark/2/text/aHR0cDovL2Jsb2cuY3 ...

  8. 2016/05/25 PHP mysql_insert_id() 函数 返回上一步 INSERT 操作产生的 ID

    定义和用法 mysql_insert_id() 函数返回上一步 INSERT 操作产生的 ID. 如果上一查询没有产生 AUTO_INCREMENT 的 ID,则 mysql_insert_id() ...

  9. BZOJ 4976: 宝石镶嵌 背包

    4976: 宝石镶嵌 Time Limit: 2 Sec  Memory Limit: 128 MB Description 魔法师小Q拥有n个宝石,每个宝石的魔力依次为w_1,w_2,...,w_n ...

  10. Mac OS用docker Desktop安装单节点kubernetes

    方案: 安装方式:阿里云minikube,k8s官方minikube,kubeadm, docker Desktop中自带第k8s 安装环境:在linux虚拟机中安装k8s,在macos中安装k8s, ...