网站推广的基本方法是哪四个,巩义网站建设费用,静态网页有哪些,企业网站建设情况汇报今天解决的是#xff1a;Mybatisplus集成pringboot完成分页功能
#x1f6f4;#x1f6f4;#x1f6f4; 之前一直用Pagehelper#xff0c;迫于无奈pagehelper与springboot冲突太多#xff0c;就改了MP自带的分页
#x1f388;引入依赖
引入mybatisplus依赖 depen…今天解决的是Mybatisplus集成pringboot完成分页功能 之前一直用Pagehelper迫于无奈pagehelper与springboot冲突太多就改了MP自带的分页
引入依赖
引入mybatisplus依赖 dependencygroupIdcom.baomidou/groupIdartifactIdmybatis-plus-boot-starter/artifactIdversion3.5.2/version/dependency分页插件配置类
温馨提醒这个必不可少
public class MybatisPlusConfig{/*** mybatisplus 分页配置*/Beanpublic MybatisPlusInterceptor mpInterceptor(){//定义mp拦截器MybatisPlusInterceptor mpInterceptor new MybatisPlusInterceptor();//添加具体的拦截器mpInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.ORACLE));mpInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());return mpInterceptor;}}在controller中使用 ApiOperation(分页查询)GetMapping(/pageList)public PageResult pageList(RequestParam(namepostName,required false) String postName,RequestParam(name pageNo,required false) Integer pageNo,RequestParam(name pageSize,required false) Integer pageSize){PageResultListPost result new PageResult();try {if (pageNo null) pageNo 1;if (pageSize null) pageSize 5;LambdaQueryWrapperPost queryWrapper new LambdaQueryWrapper();queryWrapper.like(Post::getPostName,postName);//根据职位名模糊查询PagePost page new Page(pageNo,pageSize); //定义分页类型Page page1 postService.page(page,queryWrapper); //开始查询result.setResult(page1.getRecords());result.setTotal(page1.getTotal());result.setCurrent(page1.getCurrent());result.setPages(page1.getPages());result.setSize(page1.getSize());result.success(获取职位列表成功);} catch (Exception e) {result.error500(获取职位列表失败);}return result;}上边看懂就可以过了看不懂的具体的讲解如下 MyBatis-Plus 是一个在 MyBatis 基础上进行增强的持久层框架提供了很多便捷的功能包括分页查询。在 MyBatis-Plus 中分页查询通常需要使用 Page 对象和 PageHelper 类来实现以下是使用文字说明的分页使用方法 创建一个 Page 对象指定分页的参数比如每页显示的记录数和要查询的页码。例如 javaCopy Code
PageUser page new Page(1, 10); // 查询第1页每页10条记录在进行数据库查询时将 Page 对象传递给相应的查询方法并在查询方法中使用 Page 对象进行分页查询。例如 javaCopy Code
IPageUser userPage userMapper.selectPage(page, null);在查询结果中可以通过 userPage 对象获取分页查询的结果数据以及分页相关的信息比如总记录数、总页数等。例如 javaCopy Code
ListUser userList userPage.getRecords(); // 获取查询结果列表
long total userPage.getTotal(); // 获取总记录数
long current userPage.getCurrent(); // 获取当前页
long pages userPage.getPages(); // 获取总页数通过以上步骤就可以在 MyBatis-Plus 中实现分页查询功能。使用 Page 对象可以方便地指定分页参数而使用 IPage 接口可以获取分页查询的结果数据和分页信息。
希望这些文字说明能够帮助你理解 MyBatis-Plus 中的分页使用方法。如果还有其他问题欢迎随时提问。
总结
大功告成撒花致谢关注我不迷路带你起飞带你富。