员工信息分页查询
需求分析:系统中的员工很多的时候,如果在一个页面全部展示出来会显得比较乱,不便于查看,所以一般的系统中都会以分页的方式来展示列表数据。
程序执行过程:
(1)页面发送ajax请求,将分页查询参数(page、pageSize、name)提交到服务端
(2)服务端Controller接收页面提交的数据并调用Service查询数据
(3)Service调用Mapper操作数据库,查询分页数据
(4)Controller将查询到的分页数据响应给页面
(5)页面接收到分页数据并通过ElementUI的Table组件展示到页面上。
通过MP分页插件实现分页功能。
package com.itheima.config; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** * 配置MP的分页插件 */ @Configuration public class MybatisPlusConfig { @Bean public MybatisPlusInterceptor mybatisPlusInterceptor(){ //定义mp拦截器 MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor(); //添加具体的分页拦截器 mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor()); return mybatisPlusInterceptor; } }
在controller中进行分页查询
/** * 员工信息分页查询 * @param page * @param pageSize * @param name * @return */ @GetMapping("/page") public R<Page> page(int page, int pageSize, String name){ // log.info("page:{}, pageSize:{}, name:{}", page, pageSize, name); //构造分页构造器 Page pageInfo = new Page(page, pageSize); //构造条件构造器 LambdaQueryWrapper<Employee> queryWrapper = new LambdaQueryWrapper<Employee>(); //添加一个过滤条件 queryWrapper.like(name!=null, Employee::getName, name); //添加一个排序条件 queryWrapper.orderByDesc(Employee::getUpdateTime); //执行查询,查询后page内部会将查询结果进行封装到pageInfo中 employeeService.page(pageInfo, queryWrapper); return R.success(pageInfo); }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· NetPad:一个.NET开源、跨平台的C#编辑器
· 面试官:你是如何进行SQL调优的?