1.pom中添加依赖包

         <!--pageHelper基本依赖 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.2</version>
</dependency>
<!-- 在我的实验中不加这两个依赖分页不会成功 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-autoconfigure</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency>

2.配置分页插件

  下面二者选一配置

2.1.application.properties配置

  在application.properties文件中添加如下配置

 #分页插件
pagehelper.helper-dialect=MYSQL
pagehelper.reasonable=true
pagehelper.support-methods-arguments=true
pagehelper.params=count=countSql

2.2.配文件配置对象

 package com.qiaXXXXXX.config;

 import com.github.pagehelper.PageHelper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import java.util.Properties; /**
* @Copyright (C) 四川XXXX
* @Author: LI
* @Date: 7/1 11:01
* @Description:
*/
@Configuration
public class PageHelperConfig {
@Bean
public PageHelper getPageHelper() {
PageHelper pageHelper = new PageHelper();
Properties properties = new Properties();
properties.setProperty("helperDialect", "mysql");
properties.setProperty("reasonable", "true");
properties.setProperty("supportMethodsArguments", "true");
properties.setProperty("params", "count=countSql");
pageHelper.setProperties(properties);
return pageHelper;
} }

3.分页实现

    @Override
public PageInfo<MyOrderVo> getMyOrder(MyOrderObj obj) {
if (StringUtils.isEmpty(obj.getQueryMonth())) {
String endMonth = DateUtil.getEndMonth();
obj.setStartMonth(DateUtil.getStartMonth(endMonth));
obj.setEndMonth(endMonth);
} else {
obj.setStartMonth(null);
obj.setEndMonth(null);
}
//设置分页参数
PageHelper.startPage(obj.getPageNo(), obj.getPageSize()); //查询列表数据
List<MyOrderVo> list = userCenterMapper.getMyOrder(obj); //获取分页对象
PageInfo<MyOrderVo> pageInfo = new PageInfo<>(list);
return pageInfo;
}

  注意:有了分页插件,sql语句不需要写limit,插件会在执行的sql中自动添加,也不需要自己单独写count语句获取总共条数,分页插件会自动获取.

SpringBoot集成MyBatis的分页插件PageHelper--详细步骤的更多相关文章

  1. SpringBoot集成MyBatis的分页插件 PageHelper

    首先说说MyBatis框架的PageHelper插件吧,它是一个非常好用的分页插件,通常我们的项目中如果集成了MyBatis的话,几乎都会用到它,因为分页的业务逻辑说复杂也不复杂,但是有插件我们何乐而 ...

  2. SpringBoot集成MyBatis的分页插件PageHelper(回头草)

    俗话说:好

  3. SpringBoot集成MyBatis的分页插件PageHelper

    俗话说:好

  4. SpringBoot整合MyBatis的分页插件PageHelper

    1.导入依赖(maven) <dependency> <groupId>com.github.pagehelper</groupId> <artifactId ...

  5. Mybatis的分页插件PageHelper

    Mybatis的分页插件PageHelper 项目地址:http://git.oschina.net/free/Mybatis_PageHelper  文档地址:http://git.oschina. ...

  6. Spring Boot系列教程八: Mybatis使用分页插件PageHelper

    一.前言 上篇博客中介绍了spring boot集成mybatis的方法,基于上篇文章这里主要介绍如何使用分页插件PageHelper.在MyBatis中提供了拦截器接口,我们可以使用PageHelp ...

  7. Spring Boot系列教程十一: Mybatis使用分页插件PageHelper

    一.前言 上篇博客中介绍了spring boot集成mybatis的方法,基于上篇文章这里主要介绍如何使用分页插件PageHelper.在MyBatis中提供了拦截器接口,我们可以使用PageHelp ...

  8. Mybatis之分页插件pagehelper的简单使用

    最近从家里回来之后一直在想着减肥的事情,一个月都没更新博客了,今天下午没睡午觉就想着把mybatis的分页插件了解一下,由于上个月重新恢复了系统,之前创建的项目都没了,又重新创建了一个项目. 一.创建 ...

  9. Spring Boot集成MyBatis与分页插件

    Maven依赖: <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>p ...

随机推荐

  1. 在 json4s 中自定义CustomSerializer

    到目前为止,Scala 环境下至少存在6种 Json 解析的类库,这里面不包括 Java 语言实现的 Json 类库.所有这些库都有一个非常相似的抽象语法树(AST).而 json4s 项目旨在提供一 ...

  2. Python中,我该如何切分字符串后保留分割符?

    原文来源:https://stackoverflow.com/questions/2136556/in-python-how-do-i-split-a-string-and-keep-the-sepa ...

  3. k8s记录-node组件部署(十)

    1)CA 证书配置登录 192.168.0.1 app 用户下cd ssl/kubernetes#注意修改 KUBE_HOME,BOOTSTRAP_TOKEN #与 3.5 3)token 一致,KU ...

  4. word 条件多项式公式对齐

    条件多项式公式对齐 觉得有用的话,欢迎一起讨论相互学习~Follow Me 对于使用word编写具有多个多项式的公式时,经常会有所偏移 最不优雅的方式就是使用逗号进行分隔和排版使其公式上下对齐 第二种 ...

  5. linux下 tab键失效 -bash: !ref: 为绑定变量

    报错现象: Linux环境下,按Tab键进行补全时出现上图情况. [root@worker2 cjj]# vim /et-bash: !ref: 为绑定变量 -bash: !ref: 为绑定变量 -b ...

  6. OSI七层与TCP/IP四层(小结)

    OSI 七层模型 我们一般使用的网络数据传输由下而上共有七层,分别为物理层.数据链路层.网络层.传输层.会话层.表示层.应用层,也被依次称为 OSI 第一层.第二层.⋯⋯. 第七层. 各层功能简介 1 ...

  7. myeclipse An internal error occurred during: "Initialize metrics".

    重新安装的myeclipse,在打开的时候弹出:    An internal error occurred during: "Initialize metrics". com/g ...

  8. Linux 就该这么学 CH02新手必须掌握的Linux命令

    0 概述 本章内容如下 强大的shell. 帮助文档命令(1) 系统工作命令(10) 系统状态监测命令(8) 工作目录切换命令(3) 文本文件编辑命令(9) 文件目录管理命令(7) 打包压缩或搜索命令 ...

  9. Oracle Spatial分区应用研究之八:不同分区粒度在1.5亿要素量级下的查询性能

    以土地调查地类图斑层作为测试数据,共计约1.5亿条要素.随机生成90次各比例尺的查询范围,在ORACLE 11gr2数据库中进行空间查询,记录查询耗时.最后计算平均值和第90百分位数,结果如下图所示: ...

  10. Flume和 Sqoop

    Sqoop简介 Sqoop是一种旨在有效地在Apache Hadoop和诸如关系数据库等结构化数据存储之间传输大量数据的工具 原理: 将导入或导出命令翻译成Mapreduce程序来实现. 在翻译出的M ...