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 ...
随机推荐
- python3和python2编码拾遗
py2编码 tr和unicode str和unicode都是basestring的子类.严格意义上说,str其实是字节串,它是unicode经过编码后的字节组成的序列.对UTF-8编码的str'苑'使 ...
- xkl的各种沙雕低错
13,特判判掉20分算不算? 12,linux用c++11编译: g++ -std=c++11 -o a a.cpp g++ a.cpp -std=c++11 -o a //g++ a.cpp -st ...
- eclipse查看源码的配置
1.打开eclipse软件,点击window-preference 2.在弹出框中选择java-Installed JRES,选中的默认就行,然后点一下选中的,点击edit 3.弹出框中选择第二个,展 ...
- Parse:App开发必备 让应用开发效率提高上百倍
Parse一个应用开发工具, 是由Y Combinator所孵化的创业公司.使用Parse能把效率提高10倍到100倍.通常情况下,从开发用户到推广用户需要花几周时间,用了Parse则只需几小时.[U ...
- fatal error U1087: cannot have : and :: dependents for same target Stop.
转自VC错误:http://www.vcerror.com/?p=72 问题描述: 完成后编译,发现有错误 D:\WinDDK\7600.16385.1\bin\makefile.new(7117) ...
- POJ-1502-MPI Maelstrom-dijkstra+输入处理
BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distribute ...
- 配置vue项目的自定义config.js
[1]不采用脚手架的config文件夹中的配置文件 [2]在static文件夹下,自定义一个congfig.js文件 // 配置开发环境下服务器地址 window.Glod = { pmsApiUrl ...
- LINUX挂接Windows文件共享
Windows网络共享的核心是SMB/CIFS,在linux下要挂接(mount)windows的磁盘共享,就必须安装和使用samba 软件包.现在流行的linux发行版绝大多数已经包含了samba软 ...
- JS规则 编程练习 考考大家的数学,计算以下计算公式的结果。然后在浏览器中运行一下,看看结果是否跟你的结果一致。
编程练习 考考大家的数学,计算以下计算公式的结果.然后在浏览器中运行一下,看看结果是否跟你的结果一致. 任务 第一步: 在 ? 处填写你的答案. 第二步: 填写完成后,运行一下,看看是不是跟你填写的 ...
- PCA降维2
前言 本文为模式识别系列第一篇,主要介绍主成分分析算法(Principal Component Analysis,PCA)的理论,并附上相关代码.全文主要分六个部分展开: 1)简单示例.通过简单的例子 ...