springboot mybatis的pagehelper分页
maven repositary里,分页组件常用的有两个
com.github.pagehelper » pagehelper-spring-boot-starter
com.github.pagehelper » pagehelper

躺了很多坑,记录一个能够成功的方式:
===============================分割线========================
1.在pom.xml中引入依赖:选择pagehelper的4.2.x版本(如果选了5.1.2,我就不知道咋配置,网上没找到)
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.2.</version>
</dependency>
2.配置类,这是4.x.x版本的写法,如果是5.1.2,就不能像下面这样写(不会生效)
package com.yggdrasill.framework; import com.github.pagehelper.PageHelper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Properties; @Configuration
public class PageMybatisConf {
@Bean
public PageHelper pageHelper() {
System.out.println("MyBatisConfiguration.pageHelper()");
PageHelper pageHelper = new PageHelper();
Properties p = new Properties();
p.setProperty("offsetAsPageNum", "true");
p.setProperty("rowBoundsWithCount", "true");
p.setProperty("reasonable", "true");
p.setProperty("dialect","postgresql");
pageHelper.setProperties(p);
return pageHelper;
}
}
3.调用代码
public PageInfo<Slave> queryApiSlaveList(Pager<Slave> page) {
// PageHelper.startPage(page,pageSize);开启分页插件,放在查询语句上面 帮助生成分页语句
PageHelper.startPage(page.getPage(), page.getPageSize());//1,10
List<Slave> listSlave = slaveMapper.selectAll();
// 封装分页之后的数据 返回给客户端展示 PageInfo做了一些封装 作为一个类
PageInfo<Slave> pageInfoUser = new PageInfo<Slave>(listSlave);
return pageInfoUser;
}
效果如图

完成!!!
===================================================================
ps:不用在application.properties配置那几个参数了,入如果是 pagehelper-spring-boot-starter ,则需要配置
pagehelper.helperDialect=postgresql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql
pagehelper.page-size-zero=true
至于 pagehelper-spring-boot-starter 方式,可参考 https://blog.csdn.net/csdn_huzeliang/article/details/79350425
springboot mybatis的pagehelper分页的更多相关文章
- SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页
SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页 **SpringBoot+Mybatis使用Pagehelper分页插件自动分页,非常好用,不用在自己去计算和组装了. ...
- springboot+mybatis使用PageHelper分页
项目结构和spring搭建mybatis请参考springboot整合mybatis.在这个基础上配置分页. 一:导入PageHelper依赖 <dependency> <group ...
- Mybatis的PageHelper分页插件的PageInfo的属性参数,成员变量的解释,以及页面模板
作者:个人微信公众号:程序猿的月光宝盒 //当前页 private int pageNum; //每页的数量 private int pageSize; //当前页的数量 private int si ...
- SpringBoot+Mybatis+ Druid+PageHelper 实现多数据源并分页
前言 本篇文章主要讲述的是SpringBoot整合Mybatis.Druid和PageHelper 并实现多数据源和分页.其中SpringBoot整合Mybatis这块,在之前的的一篇文章中已经讲述了 ...
- Springboot 系列(十二)使用 Mybatis 集成 pagehelper 分页插件和 mapper 插件
前言 在 Springboot 系列文章第十一篇里(使用 Mybatis(自动生成插件) 访问数据库),实验了 Springboot 结合 Mybatis 以及 Mybatis-generator 生 ...
- 小白的springboot之路(十五)、mybatis的PageHelper分页插件使用
0.前言 用mybatis,那么分页必不可少,基本都是用PageHelper这个分页插件,好用方便: 1.实现 1.1.添加依赖: <!-- 3.集成 mybatis pagehelper--& ...
- springBoot mybatis mysql pagehelper layui 分页
<!-- 加入 pagehelper 分页插件 jar包--><dependency> <groupId>com.github.pagehelper</gro ...
- SpringBoot整合系列-PageHelper分页插件
原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9971043.html SpringBoot整合MyBatis分页插件PageHelper ...
- 【spring boot】14.spring boot集成mybatis,注解方式OR映射文件方式AND pagehelper分页插件【Mybatis】pagehelper分页插件分页查询无效解决方法
spring boot集成mybatis,集成使用mybatis拖沓了好久,今天终于可以补起来了. 本篇源码中,同时使用了Spring data JPA 和 Mybatis两种方式. 在使用的过程中一 ...
随机推荐
- Java Map的正确使用方式
原文:https://www.liaoxuefeng.com/article/1256136507802816 正确使用Map,只需要正确实现hashCode()和equals()就行了吗? 恐怕还不 ...
- Run Multiple Webpack Configs Sequentially
https://www.viget.com/articles/run-multiple-webpack-configs-sequentially/ const path = require('path ...
- 《hello-world》第九次团队作业:【Beta】Scrum meeting 3
项目 内容 这个作业属于哪个课程 2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 实验十三 团队作业9:Beta冲刺与团队项目验收 团队名称 <hello--wor ...
- asp、aspx、php、jsp万能密码大全【笔记】
asp aspx万能密码 1:"or "a"="a 2: ')or('a'='a 3:or 1=1-- 4:'or 1=1-- 5:a'or' 1=1-- 6: ...
- php 常用字符串函数总结
php里面自带的字符串函数,日期函数,数组函数等,有时候可以帮助我们解决很复杂的问题,运用起来也比较简单. 下面总结了一下常用的字符串函数. addcslashes — 为字符串里面的部分字符添加反斜 ...
- Linux下dstat的安装(适用任何版本)
dstat下载地址:https://pan.baidu.com/s/1jHTEoWe 1.上传后,解压: 2.进入解压后的目录:cd dstat-0.7.3/ 3.make 4.make instal ...
- 在CentOS7上面搭建GitLab服务器
首先要在CentOS系统上面安装所需的依赖:ssh.防火墙.postfix(用于邮件通知).wegt,以下这些命令也会打开系统防火墙中的HTTP和SSH端口访问. 1.安装SSH协议 安装命令:sud ...
- Pytest权威教程21-API参考-02-标记(Marks)
目录 标记(Marks) pytest.mark.filterwarnings pytest.mark.parametrize pytest.mark.skip pytest.mark.skipif ...
- ShellExecute打开文件,打开文件夹的用法
转自https://www.cnblogs.com/nxopen2018/p/11070031.html //方法1 //转换 //char msg[256]; //sprintf_s(msg, &q ...
- 【CSP模拟赛】避难向导(倍增lca&树的直径)
耐力OIer,一天7篇博客 题目描述 “特大新闻,特大新闻!全国爆发了一种极其可怕的病毒,已经开始在各个城市 中传播开来!全国陷入了巨大的危机!大量居民陷入恐慌,想要逃到其它城市以 避难!经调查显示, ...