SpringBoot集成MyBatis的分页插件PageHelper--详细步骤
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--详细步骤的更多相关文章
- SpringBoot集成MyBatis的分页插件 PageHelper
首先说说MyBatis框架的PageHelper插件吧,它是一个非常好用的分页插件,通常我们的项目中如果集成了MyBatis的话,几乎都会用到它,因为分页的业务逻辑说复杂也不复杂,但是有插件我们何乐而 ...
- SpringBoot集成MyBatis的分页插件PageHelper(回头草)
俗话说:好
- SpringBoot集成MyBatis的分页插件PageHelper
俗话说:好
- SpringBoot整合MyBatis的分页插件PageHelper
1.导入依赖(maven) <dependency> <groupId>com.github.pagehelper</groupId> <artifactId ...
- Mybatis的分页插件PageHelper
Mybatis的分页插件PageHelper 项目地址:http://git.oschina.net/free/Mybatis_PageHelper 文档地址:http://git.oschina. ...
- Spring Boot系列教程八: Mybatis使用分页插件PageHelper
一.前言 上篇博客中介绍了spring boot集成mybatis的方法,基于上篇文章这里主要介绍如何使用分页插件PageHelper.在MyBatis中提供了拦截器接口,我们可以使用PageHelp ...
- Spring Boot系列教程十一: Mybatis使用分页插件PageHelper
一.前言 上篇博客中介绍了spring boot集成mybatis的方法,基于上篇文章这里主要介绍如何使用分页插件PageHelper.在MyBatis中提供了拦截器接口,我们可以使用PageHelp ...
- Mybatis之分页插件pagehelper的简单使用
最近从家里回来之后一直在想着减肥的事情,一个月都没更新博客了,今天下午没睡午觉就想着把mybatis的分页插件了解一下,由于上个月重新恢复了系统,之前创建的项目都没了,又重新创建了一个项目. 一.创建 ...
- Spring Boot集成MyBatis与分页插件
Maven依赖: <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>p ...
随机推荐
- cps在jenkins构建报错
修改ares的版本号即可,改为2.0.1.14-20191126-RELEASE
- Nginx修改时间戳
1.安装nginx,注意不要安装nginx-common或者nginx-full sudo apt-get install nginx sudo apt-get install nginx-commo ...
- Mac AXURE9 汉化
1.下载汉化文件 https://pan.baidu.com/s/1qE0ZSvf210WLMfvi8RlMpg 2.把lang文件放在Resources文件夹下 3.重新打开Axure就ok了
- Intellij IDEA设置类注释和方法注释
背景:工欲善其事必先利其器,如果不能把工具用熟练了, 感觉很是别扭. 参考:IntelliJ IDEA设置类注释和方法注释 IntelliJ IDEA 中创建类的时候,可以直接自动给类加注释的设置,以 ...
- Math 类
Math 类 java.lang.Object java.lang.Math 方法签名 public final class Math extends Object public static fin ...
- Fineui alert去掉关闭按钮,去掉X
参考:http://fineui.com/bbs/forum.php?mod=viewthread&tid=7455&highlight=alert http:// ...
- PostgreSQL 参数调整(性能优化)
昨天分别在外网和无外网环境下安装PostgreSQL,有外网环境下安装的相当顺利.但是在无外网环境下就是两个不同的概念了,可谓十有八折.感兴趣的同学可以搭建一下. PostgreSQL安装完成后第一件 ...
- [IOT] - 使用 .Net Core 操作 GPIO 引脚点亮 LED 灯泡
1. 在 VS 2019 中创建 .Net Core 控制台应用程序,使用 Nuget 安装程序包: System.Device.GpioIot.Device.Bindings 2. 更新 Main ...
- BJFU-216-基于链式存储结构的图书信息表的修改
#include<stdio.h> #include<stdlib.h> #define MAX 100 typedef struct Book{ double no; cha ...
- Window中C++进行精确计时的方法
嗯,程序员一个永恒的追求就是性能吧? 为了衡量性能,自然需要计时. 奈何无论C标准库还是C++标准库,因为通用性的考虑,其time API精度都不高.基本都是毫秒级的. 所以如果要真正精确地衡量程序的 ...