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. Java:JSON和Map相互转换

    Java:JSON与Map相互转换 需要jar包:jackson-core-2.6.0.jar,jackson-databind-2.6.0.jar,jackson-annotations-2.6.0 ...

  2. python MySQLdb 字典(dict)结构数据插入mysql

    背景: 有时候直接操作数据库字段比较多,一个个写比较麻烦,而且如果字段名跟数据库一致,那生成为字典后,是否能直接使用字典写入数据库呢,这样会方便很多,这里简单介绍一种方法. 实例: 1. 假设数据库表 ...

  3. npm 更换阿里云镜像

    来源:https://blog.csdn.net/a249040113/article/details/81567430 npm安装插件过程:从http://registry.npmjs.org下载对 ...

  4. python万能消费框架,新增7种中间件(或操作mq的包)和三种并发模式。

    新增的中间件和并发模式见注释. 消息队列中间件方面celery支持的,都要支持.并发模式,celery支持的都要支持. 从无限重复相似代码抽取框架,做成万能复用,是生产力的保障. 使用模板模式使加新中 ...

  5. springboot放到linux启动报错:The temporary upload location [/tmp/tomcat.8524616412347407692.8111/work/Tomcat/localhost/ROOT/asset] is not valid

    1.背景 笔者的springboot在一个非root用户环境下运行,这种环境下可以保证不被潜在的jar/开源框架漏洞提权. 比如在防火墙上把外网访问来的443端口映射到本地8443的java web端 ...

  6. LeetCode_459. Repeated Substring Pattern

    459. Repeated Substring Pattern Easy Given a non-empty string check if it can be constructed by taki ...

  7. Xcode7.2真机测试问题"The account 'appleID ' has no team with ID ‘’

     在Xcode7(测试版)提出免费真机测试的时候,我立刻在网上搜寻测试步骤,很简单,按照步骤走就可以. 但在7.2以后,突然我的iPhone不能真调了!提示"The account 'app ...

  8. django:删除表后怎么重新数据迁移生成表

    1.将对应app下的migrations文件夹下面的除了__init__.py文件外全部删除 2.delete from django_migrations where app='app_name' ...

  9. WinForm自动记录从上次关闭位置启动窗体

    次功能主要是通过在注册表中读写窗体的Location属性来实现的.在窗体关闭前处理窗体的FormClosed事件,将窗体的Location属性值写入注册表,然后在窗体的Load事件中从注册表中读取保存 ...

  10. centos7安装配置MariaDB10

    1:添加 MariaDB yum 仓库 vi /etc/yum.repos.d/MariaDB.repo在该文件中添加以下内容保存: [mariadb] name = MariaDB baseurl ...