SpringBoot-mybatis-plus 分页
前言:
想必数据分页对于每一个程序员并不陌生,针对分页查询功能代码实现上;肯定是代码简洁明了且能达到分页的效果会更好!
现在我将基于SpringBoot - mybatisPlus分页查询的方法总结如下;废话不多说,直接上代码:
一、Mybatis-Plus的依赖:
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3.1</version>
</dependency>
二、编写分页config
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; /**
* @Project:
* @Description:
* @Auther: songwp
* @Date: 2022/7/30
**/
@Configuration
@MapperScan("com.songwp.mapper")
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
- 我们要将mybatisPlusInterceptor 这个方法注册到Bean里面,不然我们的插件就会失效。
- 使用@MapperScan这个注解,让系统扫描我们的Mapper类。注意一定要指定正确的Mapper地址。
- 在类方法上上面使用注解:@Configuration表面这是一个config类
三、测试代码块
@Resource
SalaryDetailMapperExtend salaryDetailMapperExtend; public Page<SalaryDetail> selectSalaryDetailPage(@RequestParam(defaultValue = "0")Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize,
String name){
Page<SalaryDetail> salaryDetailPage = salaryDetailMapperExtend
.selectPage(new Page<>(pageNum, pageSize), Wrappers.<SalaryDetail>lambdaQuery()
// 降序排序
.orderByDesc(SalaryDetail::getId));
// 升序排序 (数据库查询出来的数据 默认是 asc 升序排序)
// .orderByAsc(SalaryDetail::getId))
// 根据name模糊查询并且按照id降序查询
//.orderByDesc(SalaryDetail::getId).like(SalaryDetail::getName,name);
// 根据name查询并且按照id降序查询
//.orderByDesc(SalaryDetail::getId).eq(SalaryDetail::getName,name);
log.info("[工资详情信息分页代码测试] pageNum: {} ---salaryDetailPage {}---- pageSize: {}",pageNum,salaryDetailPage,pageSize); return salaryDetailPage;
}
四:数据查询展示:

SpringBoot-mybatis-plus 分页的更多相关文章
- springboot + mybatis配置分页插件
一:使用pagehelper配置分页插件 1:首先配置springboot +mybatis框架 参考:http://www.cnblogs.com/liyafei/p/7911549.html 2 ...
- SpringBoot+Mybatis+Pagehelper分页
1.pom.xml <!-- mybatis分页插件 --> <dependency> <groupId>com.github.pagehelper</gro ...
- springboot mybatis pagehelper 分页问题
1:添加依赖 compile group: 'com.github.pagehelper', name: 'pagehelper-spring-boot-starter', version: '1.2 ...
- springboot+mybatis集成分页功能
1.使用idea搭建srpingboot项目 在pom.xml文件中引入如下的依赖: <dependency> <groupId>org.springframework.boo ...
- springboot + mybatis +pageHelper分页排序
今天下午写查出来的数据的排序,原来的数据没有排序,现在把排序功能加上...原来用的,是xml中的sql动态传参 ,,1个小数没有弄出来,果断放弃... 网上百度一下,发现用pageHelper 可以 ...
- SpringBoot+MyBatis+PageHelper分页无效
POM.XML中的配置如下:<!-- 分页插件 --><!-- https://mvnrepository.com/artifact/com.github.pagehelper/pa ...
- SpringBoot集成MyBatis的分页插件 PageHelper
首先说说MyBatis框架的PageHelper插件吧,它是一个非常好用的分页插件,通常我们的项目中如果集成了MyBatis的话,几乎都会用到它,因为分页的业务逻辑说复杂也不复杂,但是有插件我们何乐而 ...
- SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页
SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页 **SpringBoot+Mybatis使用Pagehelper分页插件自动分页,非常好用,不用在自己去计算和组装了. ...
- SpringBoot+Mybatis+PageHelper实现分页
SpringBoot+Mybatis+PageHelper实现分页 mybatis自己没有分页功能,我们可以通过PageHelper工具来实现分页,非常简单方便 第一步:添加依赖 <depend ...
- spring-boot + mybatis +pagehelper 使用分页
转自:https://segmentfault.com/a/1190000015668715?utm_medium=referral&utm_source=tuicool 最近自己搭建一个sp ...
随机推荐
- Scala 简单分词求和
1 package chapter07 2 3 object Test17_CommonWordCount { 4 def main(args: Array[String]): Unit = { 5 ...
- Python BeautifulSoup 简单使用方法
- 并发框架 LMAX Disruptor
Introduction Michael Barker edited this page on 2 Mar 2015 · 8 revisions The best way to understan ...
- DIY 3 种分库分表分片算法,自己写的轮子才吊!
大家好,我是小富- 前言 本文是<ShardingSphere5.x分库分表原理与实战>系列的第六篇,书接上文实现三种自定义分片算法.通过自定义算法,可以根据特定业务需求定制分片策略,以满 ...
- #dp,二项式反演,容斥#CF285E Positions in Permutations
题目 问有多少个长度为 \(n\) 的排列 \(P\) 满足 \(|P_i-i|=1\) 的 \(i\) 的个数恰好为 \(k\) 个 分析 设 \(dp_{i,j,k}\) 表示前 \(i\) 个数 ...
- #数学期望,状压dp,记忆化搜索#nssl 1468 V
分析 赛时写了个\(O(n!)\)的纯暴力,其实我现在才发现\(O(n!)\)的暴力一般都能用\(O(n2^n)\)的状压dp解决 但是其实不是每个状态都能被访问到,所以若\(n\)过大,用\(map ...
- #CDQ分治,单调栈,双指针#BZOJ 4237 稻草人 AT1225 かかし
洛谷传送门 BZOJ 4237 稻草人 题意 在一个平面直角坐标系上给出\(n\)个点, 问有多少个点对\((i,j)\)满足\(x_i<x_j,y_i<y_j\), 而且对于\(n\)个 ...
- 三步就能在OpenHarmony中实现车牌识别
介绍 本车牌识别项目是基于开源项目 EasyPR(Easy to do Plate Recognition)实现.EasyPR 是一个开源的中文车牌识别系统,基于 OpenCV 开源库开发. 本项目使 ...
- k8s之emptyDir存储卷
一.简介 emptyDir卷是最简单的卷,主要用于存储临时数据,当pod生命周期结束,emptyDir卷也就销毁. emptyDir卷应用场景一般是pod中多个容器共享数据,即在pod中定义一个emp ...
- WAF网站访问限制
请参考:https://www.cnblogs.com/yangyangblog/p/14930159.html 文件下载的地方可以网络搜索,这里提供IIS7 WINDOWS64位版本:https:/ ...