当前位置: 首页 > news >正文

MybatisPlus分页插件使用

一. 效果展示

在这里插入图片描述

二. 代码编写

2.1 pom

<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.4.2</version>
</dependency>

2.2 添加配置类

@Configuration
@MapperScan("scan.your.mapper.package")
public class MybatisPlusConfig {/*** 添加分页插件*/@Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor() {MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));return interceptor;}
}

2.3 前端选择条件实体

@Data
public class ApproveGetDto {// 导入开始时间private String startTime;// 导入结束时间private String endTime;// 审批状态private Integer approveStatus;// 所属分部private List<String> division;// 人员范围private String personScope;// 导入人工号private String importPernr;// 离职员工工号private String quitPernr;// 当前页码private Integer currentPage;// 每页展示条数private Integer pageSize; 
}

2.4 mapper添加分页方法

/*** 根据选择条件进行分页* @param page mybatus-plus提供的分页插件,必须位于第一个参数* @param approveGetDto 选择条件* @return vo对象*/
Page<UserVo> selectPageVo(@Param("page") Page<UserVo> page,@Param("approveGetDto") ApproveGetDto approveGetDto);

2.5 sql映射文件

<select id="selectPageVo"  resultMap="UserVo">select * from t_user<where><if test="startTime != null and endTime != null">AND importTime between #{startTime} and #{endTime}</if><if test="division != null and division.size() > 0">AND division in<foreach item="item" collection="division" open="(" separator="," close=")">#{item}</foreach></if><if test="personScope != null and personScope != ''">AND person_scope = #{personScope}</if><if test=" importPernr != null and importPernr != ''">AND originator_pernr = #{importPernr}</if><if test="quitPernr != null and quitPernr != '' ">AND quit_Pernr = #{quitPernr}</if></where>
</select>

2.6 service

Page<UserVo> findPageVo(ApproveGetDto approveGetDto);

2.7 serviceImpl

@Override
public Page<UserVo> selectPageVo(ApproveGetDto approveGetDto) {Page<UserVo> page = new Page<UserVo>(approveGetDto.getCurrentPage,approveGetDto.getPageSize);userMapper.selectPageVo(page,approveGetDto);return page;
}

2.8 controller

@GetMapping("/page")
public Result<Page<UserVo>> pageInfo(ApproveGetDto approveGetDto){Page<UserVo> userVo = userService.findPageVo(approveGetDto);return Result.success(userVo);
}

2.9 前端获取参数

getList() {this.loading = truethis.queryParams.currentPage = this.currentPagethis.queryParams.pageSize = this.pageSizeapproveDataList(this.queryParams).then(response => {if (response.code == 200) {if (response.data.total == 0) {this.approveDataList = response.data.rowsthis.$alert('未查询到符合条件的数据,请检查查询条件后重试!', '查询结果', {confirmButtonText: '确定',})this.loading = false} else {// 获取总记录数this.totalCount = response.data.total// 获取当前页数据this.approveDataList = response.data.recordsthis.$message({message: '查询成功',type: 'success'})this.loading = false}} else {this.loading = falsethis.approveDataList = []this.$message({message: '查询失败',type: 'erro'})}})
}

三. 参数

在这里插入图片描述

System.out.println(page.getRecords());//获取分页记录
System.out.println(page.getPages());//总页数
System.out.println(page.getTotal());//总记录数
System.out.println(page.hasNext());//是否有下一页
System.out.println(page.hasPrevious());//是否有上一页
http://www.lryc.cn/news/161179.html

相关文章:

  • Linux指令二【进程,权限,文件】
  • uni-app运行到微信开发者工具-没有打印的情况
  • 由前端接口入门学习后端的controller层
  • HJ71 字符串通配符
  • ffmpeg 开发笔记
  • 一种基于注意机制的快速、鲁棒的混合气体识别和浓度检测算法,配备了具有双损失函数的递归神经网络
  • [运维|系统] go程序设置开机启动踩坑笔记
  • CRC原理介绍及STM32 CRC外设的使用
  • Python 操作 Word
  • Linux--进程创建(fork)-退出--孤儿进程
  • LeetCode 热题 HOT 100:链表专题
  • Redis发布订阅
  • 在Windows操作系统上安装PostgreSQL数据库
  • 【云原生】Kubeadmin部署Kubernetes集群
  • Java中wait和notify详解
  • 算法竞赛个人注意事项
  • ClickHouse和Doris超大数据集存储
  • 02-Flask-对象初始化参数
  • 第5篇 vue的通信框架axios和ui框架-element-ui以及node.js
  • RabbitMQ 知识点解读
  • SimVODIS++: Neural Semantic Visual Odometry in Dynamic Environments 论文阅读
  • 7.Xaml Image控件
  • Solidity 小白教程:11. 构造函数和修饰器
  • 静态工厂模式,抽象工厂模式,建造者模式
  • 【动手学深度学习笔记】--门控循环单元GRU
  • 浅析linux异步io框架 io_uring
  • 访问者模式的一个使用案例——文档格式转换
  • 【MySql】数据库的聚合查询
  • Linux初探 - 概念上的理解和常见指令的使用
  • 苹果上架Guideline 4.3 - Design