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分页的更多相关文章

  1. SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页

    SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页 **SpringBoot+Mybatis使用Pagehelper分页插件自动分页,非常好用,不用在自己去计算和组装了. ...

  2. springboot+mybatis使用PageHelper分页

    项目结构和spring搭建mybatis请参考springboot整合mybatis.在这个基础上配置分页. 一:导入PageHelper依赖 <dependency> <group ...

  3. Mybatis的PageHelper分页插件的PageInfo的属性参数,成员变量的解释,以及页面模板

    作者:个人微信公众号:程序猿的月光宝盒 //当前页 private int pageNum; //每页的数量 private int pageSize; //当前页的数量 private int si ...

  4. SpringBoot+Mybatis+ Druid+PageHelper 实现多数据源并分页

    前言 本篇文章主要讲述的是SpringBoot整合Mybatis.Druid和PageHelper 并实现多数据源和分页.其中SpringBoot整合Mybatis这块,在之前的的一篇文章中已经讲述了 ...

  5. Springboot 系列(十二)使用 Mybatis 集成 pagehelper 分页插件和 mapper 插件

    前言 在 Springboot 系列文章第十一篇里(使用 Mybatis(自动生成插件) 访问数据库),实验了 Springboot 结合 Mybatis 以及 Mybatis-generator 生 ...

  6. 小白的springboot之路(十五)、mybatis的PageHelper分页插件使用

    0.前言 用mybatis,那么分页必不可少,基本都是用PageHelper这个分页插件,好用方便: 1.实现 1.1.添加依赖: <!-- 3.集成 mybatis pagehelper--& ...

  7. springBoot mybatis mysql pagehelper layui 分页

    <!-- 加入 pagehelper 分页插件 jar包--><dependency> <groupId>com.github.pagehelper</gro ...

  8. SpringBoot整合系列-PageHelper分页插件

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9971043.html SpringBoot整合MyBatis分页插件PageHelper ...

  9. 【spring boot】14.spring boot集成mybatis,注解方式OR映射文件方式AND pagehelper分页插件【Mybatis】pagehelper分页插件分页查询无效解决方法

    spring boot集成mybatis,集成使用mybatis拖沓了好久,今天终于可以补起来了. 本篇源码中,同时使用了Spring data JPA 和 Mybatis两种方式. 在使用的过程中一 ...

随机推荐

  1. LeetCode初级算法--字符串02:字符串中的第一个唯一字符

    LeetCode初级算法--字符串02:字符串中的第一个唯一字符 搜索微信公众号:'AI-ming3526'或者'计算机视觉这件小事' 获取更多算法.机器学习干货 csdn:https://blog. ...

  2. k8s安装之kube-state-metrics.yaml

    概述 已经有了cadvisor.heapster.metric-server,几乎容器运行的所有指标都能拿到,但是下面这种情况却无能为力: 我调度了多少个replicas?现在可用的有几个? 多少个P ...

  3. 03 c++中this指针

    概念: 成员函数:在类中定义的函数.普通函数无法被继承,成员函数可以被继承.友元函数相当于普通函数. 友元函数不是类的组成,没有this指针,必须将成员函数操作符作为参数传递对象. 在c++中成员函数 ...

  4. vue中url带有#号键,去除方法

    在写vue项目中,发现路由跳转总是带有#,在获取数据中带来不必要的麻烦,如果我们不希望 路由中出现 # ,那怎么办呢? 解决办法: 在router ---->index 中 添加代码   mod ...

  5. SSM整合Dubbo登陆案例

    登陆案例 一.创建Service项目存放共同数据 1.1  创建实体类 private long id; private String loginName; private String userNa ...

  6. Cogs 376. [IOI2002]任务安排(后效性DP)

    [IOI2002]任务安排 ★☆ 输入文件:batch.in 输出文件:batch.out 简单对比 时间限制:1 s 内存限制:128 MB N个任务排成一个序列在一台机器上等待完成(顺序不得改变) ...

  7. Processing 字体变形

    在Processing中做字体变形通常需要有以下基础知识: 1.PGraphics对象 2.图片像素化 制作过程也不复杂,代码如下: color ELLIPSE_COLOR = color(0); c ...

  8. deepin 深度Linux系统 15.11 链接蓝牙鼠标问题

    不知道为毛就是搜索不到,好吧只能用老方法,那就是不使用deepin系统自带的面板进行管理 用下面的命令进行安装配置即可 sudo apt install bluetooth blueman bluem ...

  9. PowerBuilder 这么古老的语言(破解一软件)

     PowerBuilder 这么古老的语言,编辑器用的6.5的好古老的气息,好吧破解木有兴趣了, 不过嘛可以说一下破解思路,这个系统使用的是圣天狗,联网版的. 复制狗(暴力,没技术味道) 模拟狗(也是 ...

  10. 7、CentOS6 编译安装

    LAMP组合的编译安装: httpd*php modules:把php编译成httpd的DSO对象 prefork:libphp5 event,worker : libphp5-zts cgi fpm ...