mybatis配合pagehelper分页助手查询
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分页助手查询的更多相关文章
- SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页
SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页 **SpringBoot+Mybatis使用Pagehelper分页插件自动分页,非常好用,不用在自己去计算和组装了. ...
- Mybatis的PageHelper分页插件的PageInfo的属性参数,成员变量的解释,以及页面模板
作者:个人微信公众号:程序猿的月光宝盒 //当前页 private int pageNum; //每页的数量 private int pageSize; //当前页的数量 private int si ...
- 【spring boot】14.spring boot集成mybatis,注解方式OR映射文件方式AND pagehelper分页插件【Mybatis】pagehelper分页插件分页查询无效解决方法
spring boot集成mybatis,集成使用mybatis拖沓了好久,今天终于可以补起来了. 本篇源码中,同时使用了Spring data JPA 和 Mybatis两种方式. 在使用的过程中一 ...
- Springboot 系列(十二)使用 Mybatis 集成 pagehelper 分页插件和 mapper 插件
前言 在 Springboot 系列文章第十一篇里(使用 Mybatis(自动生成插件) 访问数据库),实验了 Springboot 结合 Mybatis 以及 Mybatis-generator 生 ...
- Mybatis学习 PageHelper分页插件
1.Maven依赖,注意使用PageHelper时的版本必须与Mybatis版本对应 1 <!-- 添加Mybatis依赖 --> 2 <dependency> 3 <g ...
- Spring Boot整合tk.mybatis及pageHelper分页插件及mybatis逆向工程
Spring Boot整合druid数据源 1)引入依赖 <dependency> <groupId>com.alibaba</groupId> <artif ...
- 小白的springboot之路(十五)、mybatis的PageHelper分页插件使用
0.前言 用mybatis,那么分页必不可少,基本都是用PageHelper这个分页插件,好用方便: 1.实现 1.1.添加依赖: <!-- 3.集成 mybatis pagehelper--& ...
- springboot+mybatis使用PageHelper分页
项目结构和spring搭建mybatis请参考springboot整合mybatis.在这个基础上配置分页. 一:导入PageHelper依赖 <dependency> <group ...
- springboot如何集成mybatis的pagehelper分页插件
mybatis提供了一个非常好用的分页插件,之前集成的时候需要配置mybatis-config.xml的方式,今天我们来看下它是如何集成springboot来更好的服务的. 只能说springboot ...
随机推荐
- C++ 系列:交换两个数字
1. 创建中间变量 这是最快也是最简单的办法,例如: #include<stdio.h> int main(){ int a=10; int b=20; int temp; printf( ...
- java中的break continue
break语句 在任何循环语句的主体部分,均可用break控制循环的流程.break用于强行退出循环,不执行循环中剩余的语句.(break语句也在switch语句中使用) public class B ...
- Windows dir
显示目录中的文件和子目录列表. DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N] [/O[[:]so ...
- CSS——精灵技术
精灵技术产生的背景 图所示为网页的请求原理图,当用户访问一个网站时,需要向服务器发送请求,网页上的每张图像都要经过一次请求才能展现给用户. 然而,一个网页中往往会应用很多小的背景图像作为修饰,当网页中 ...
- LUOGU P4042 [AHOI2014/JSOI2014]骑士游戏 (spfa+dp)
传送门 解题思路 首先设\(f[x]\)表示消灭\(x\)的最小花费,那么转移方程就是 \(f[x]=min(f[x],\sum f[son[x]] +s[x])\),如果这个转移是一个有向无环图,那 ...
- dart中的typedef <函数别名>
typedef定义如下: typedef 给某一种特定的函数类型起了一个名字,可以认为是一个类型的别名.或者这样理解: 自己定义了一种数据类型,不过这种数据类型是函数类型,按照这种类型实例化后的对象, ...
- CCPC 2019 网络赛 HDU huntian oy (杜教筛)
1005 huntian oy (HDU 6706) 题意: 令,有T次询问,求 f(n, a, b). 其中 T = 10^4,1 <= n,a,b <= 1e9,保证每次 a,b互质. ...
- asp.net Core 获取应用程序所在目录的2种方式
//获取应用程序所在目录的2种方式(绝对,不受工作目录影响,建议采用此方法获取路径).如:d:\Users\xk\Desktop\WebApplication1\WebApplication1\bin ...
- ZOJ2562
ZOJ2562https://vjudge.net/problem/11781/origin<=n的且因子数最多的那个数做法:同因子数取最小,dfs更新答案 #include <iostr ...
- 高效开发 Dubbo?用 Spring Boot 可得劲!
不仅简化了 Dubbo 基于 xml 配置的方式,也提高了日常开发效率,甚至提升了工作幸福感. 为了节省亲爱的读者您的时间,请根据以下2点提示来阅读本文,以提高您的阅读收获效率哦. 如果您只有简单的 ...