Maven:

参考:

springBoot2.x整合pagehelper5.1.2:https://blog.csdn.net/Carlson_Chis/article/details/85637489

在pom.xml中配置依赖:

        <!-- mybatis的分页插件 -->
<!--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>

service中使用:

/**
* 根据查询条件分页并排序查询品牌信息
* @param key
* @param page
* @param rows
* @param sortBy
* @param desc
* @return
*/
public PageResult<Brand> queryBrandsByPage(String key, Integer page, Integer rows, String sortBy, Boolean desc) { // 初始化example对象
Example example = new Example(Brand.class);
Example.Criteria criteria = example.createCriteria(); // 根据name模糊查询,或者根据首字母查询
if (StringUtils.isNotBlank(key)) {
criteria.andLike("name","%" + key + "%").orEqualTo("letter",key);
} // 添加分页条件
PageHelper.startPage(page,rows); // 添加排序条件
if (StringUtils.isNotBlank(sortBy)) {
// 通过判断desc是true还是false,确定升序还是降序
example.setOrderByClause(sortBy + " " + (desc ? "desc" : "asc")); // 相当于“id desc”
} // 将查询到的结果保存在Brand类型的list中
List<Brand> brands = this.brandMapper.selectByExample(example); // 包装成pageInfo
PageInfo<Brand> pageInfo = new PageInfo<>(brands); // 包装成分页的结果集返回
return new PageResult<>(pageInfo.getTotal(),pageInfo.getList()); }

mybatis配合pagehelper分页助手查询的更多相关文章

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

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

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

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

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

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

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

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

  5. Mybatis学习 PageHelper分页插件

    1.Maven依赖,注意使用PageHelper时的版本必须与Mybatis版本对应 1 <!-- 添加Mybatis依赖 --> 2 <dependency> 3 <g ...

  6. Spring Boot整合tk.mybatis及pageHelper分页插件及mybatis逆向工程

    Spring Boot整合druid数据源 1)引入依赖 <dependency> <groupId>com.alibaba</groupId> <artif ...

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

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

  8. springboot+mybatis使用PageHelper分页

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

  9. springboot如何集成mybatis的pagehelper分页插件

    mybatis提供了一个非常好用的分页插件,之前集成的时候需要配置mybatis-config.xml的方式,今天我们来看下它是如何集成springboot来更好的服务的. 只能说springboot ...

随机推荐

  1. 什么是 Hexo?

    Hexo   文档 欢迎使用 Hexo,本文档将帮助您快速上手.如果您在使用过程中遇到问题,请查看 问题解答 中的解答,或者在 GitHub.Google Group 上提问. 什么是 Hexo? H ...

  2. 小程序template怎样渲染页面的

    template模板渲染demo wxml页面 <view class="btmcon"> <text class="btmtitle"> ...

  3. phonegap 开发指南系列----开始之前(1)

    在基于任何平台(安卓.ios等phonegap支持的平台)上做phonegap开发之前,需要安装 cordova 的 command-line interface (CLI) .CLI详细:http: ...

  4. Batch pk Shell - WindowsBatch与LinuxShell比较 [变量符号和关键字]

    原文地址:WindowsBatch与LinuxShell比较[变量符号和关键字] 一 简单实例1)batch file @echo off rem output helloworld ::  outp ...

  5. npm与cnpm两者之间的区别是什么?

    NPM(节点包管理器)是节点的包管理器,用于管理节点插件(包括安装.卸载和管理依赖关系等).).NPM是一个软件包管理工具,安装在新版本的节点上,所以我们需要安装节点. NPM的常用场景(http:/ ...

  6. JS预解析与变量提升

    预解析 JavaScript代码的执行是由浏览器中的JavaScript解析器来执行的.JavaScript解析器执行JavaScript代码的时候,分为两个过程:预解析过程和代码执行过程 预解析过程 ...

  7. day13 python-001 简介及循环、判断、复制等

    Python之路,Day1 = Python基础1 本节内容 1.Python历史简介以及安装.环境变量的配置: 2.Pycharm的简单设置: 3.变量的使用及定义: 4.获取键盘输入及打印: 5. ...

  8. chrome控制台使用jquery

    html页面中加入:<script type="text/javascript" src="http://static.fanxian.com/script/jqu ...

  9. 自定义Collection View布局

    转自answer-huang的博客 原文出自:Custom Collection View Layouts    UICollectionView在iOS6中第一次被介绍,也是UIKit视图类中的一颗 ...

  10. php算法题---对称的二叉树

    php算法题---对称的二叉树 一.总结 一句话总结: 可以在isSymmetrical()的基础上再加一个函数comRoot,函数comRoot来做树的递归判断 /*思路:首先根节点以及其左右子树, ...