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. JS项目快速压缩(windows平台)

    问题 当下JS项目都有node_modules,从而项目文件多,容量大. 如何快速压缩一个JS项目? 方法 首先对JS项目安装生产环境的依赖npm install --production. 这时不要 ...

  2. (转载)人脸识别中Softmax-based Loss的演化史

    人脸识别中Softmax-based Loss的演化史  旷视科技 近期,人脸识别研究领域的主要进展之一集中在了 Softmax Loss 的改进之上:在本文中,旷视研究院(上海)(MEGVII Re ...

  3. Python浮点数数据精度控制

    代码 import decimal from decimal import Decimal, getcontext if __name__ == '__main__': decimal.getcont ...

  4. 《深入理解Linux内核》 读书笔记

    深入理解Linux内核 读书笔记 一.概论 操作系统基本概念 多用户系统 允许多个用户登录系统,不同用户之间的有私有的空间 用户和组 每个用于属于一个组,组的权限和其他人的权限,和拥有者的权限不一样. ...

  5. python获取https并且写文件日志

    # -*- coding: utf-8 -*- import os import os.path import shutil import chardet import urllib.request ...

  6. 【MongoDB学习之四】索引 聚合 备份与恢复 监控

    环境 MongoDB 4.0 CentOS 6.5_x64 一.索引语法ensureIndex()方法基本语法格式如下所示:>db.COLLECTION_NAME.ensureIndex({KE ...

  7. SpringBoot系列教程web篇之过滤器Filter使用指南

    web三大组件之一Filter,可以说是很多小伙伴学习java web时最早接触的知识点了,然而学得早不代表就用得多.基本上,如果不是让你从0到1写一个web应用(或者说即便从0到1写一个web应用) ...

  8. CentOS 7.7安装Erlang和Elixir

    安装之前,先看一下它们的简要说明 Erlang Erlang是一种开源编程语言,用于构建对高可用性有要求的大规模可扩展的软实时系统.它通常用于电信,银行,电子商务,计算机电话和即时消息中.Erlang ...

  9. 【Linux】修改root密码

    sudo passwd root 然后提示输入两次新密码就可以了

  10. 腾讯物联网操作系统正式开源,最小体积仅1.8 KB

    9月18日,腾讯宣布将开源自主研发的轻量级物联网实时操作系统TencentOS tiny.相比市场上其它系统,腾讯TencentOS tiny在资源占用.设备成本.功耗管理以及安全稳定等层面极具竞争力 ...