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 ...
随机推荐
- bootsrap-----固定布局解析
<div class="container"> container </div> .container { .container-fixed();容器的wi ...
- CF475F meta-universe
题意:给你一个无限大矩形中有一些planet,每次可以选择某一没有planet的行或列分割开矩形(分割开以后要求矩形不为空).问最后能分割成几个矩形? 标程: #include<bits/std ...
- Myeclipse从外部导入项目时,jsp和html页面中所有的onclick="return xx()"位置均出现cannot return from outside function() or method()错误
- VS中检测数据库链接
在程序中链接数据库,总要为链接语句发愁.可以尝试在链接前,从VS中测试下链接,测试成功的话,可以直接将链接语句复制到程序中. 在VS中,选择“工具”——“连接到数据库”,如下:
- MAMP mysql无法启动 总结(以后有发现再添加)
1.错误信息Can't start server : Bind on unix socket: Address already in use 解析:主要原因是上次关闭Mysql是出现异常而导致的, 解 ...
- 02.万恶之源-python 运算符和编码
一.流程控制语句if: 第一种语法: (最基本的语法) if 条件: 代码块/结果1 结果2 # 如果条件是真(True)执行结果为1,然后结果为2,如果条件为错(False), 直接结果2. 第二种 ...
- MySQL 调优/优化的 101 个建议!
原文:http://www.monitis.com/blog/101-tips-to-mysql-tuning-and-optimization/ MySQL是一个强大的开源数据库.随着MySQL上的 ...
- 关于ueditor 文本框
遇到一个问题,需要将从ueditor中的获得的带格式的文本,从数据库中取出,在放回到 ueditor中去,但是 文本中\n总是截断字符串,出现 这种情况,后面的字符就不能算到里面去了,程序就报错了. ...
- cocos2dx触摸响应
Layer其实继承了触控的接口. 所以只需要重写一些函数即可. 在helloword类中重写: virtual bool init(); /** Callback functi ...
- C++返回引用的需求
1.重载+=操作符返回*this或者某个参数的引用可以方便链式调用,比如C++流操作就是cout<< a << b << c这样的,就是靠不停返回stream的引用 ...