springboot如何集成mybatis的pagehelper分页插件
2023-09-11 14:18:56 时间
mybatis提供了一个非常好用的分页插件,之前集成的时候需要配置mybatis-config.xml的方式,今天我们来看下它是如何集成springboot来更好的服务的。
只能说springboot的强大之处真是不容小觑。
第一步:添加依赖
第二步:配置文件简单:
第三步:编写代码:
第四步效果:
{ "status": 0, "data": { "pageNum": 1, "pageSize": 1, "size": 1, "startRow": 0, "endRow": 0, "total": 1, "pages": 1, "list": [ { "id": 26, "categoryId": 100002, "name": "Apple iPhone 7 Plus (A1661) 128G 玫瑰金色 移动联通电信4G手机", "subtitle": "iPhone 7,现更以红色呈现。", "mainImage": "241997c4-9e62-4824-b7f0-7425c3c28917.jpeg", "status": null, "price": 6999 } ], "prePage": 0, "nextPage": 0, "isFirstPage": true, "isLastPage": true, "hasPreviousPage": false, "hasNextPage": false, "navigatePages": 8, "navigatepageNums": [ 1 ], "navigateFirstPage": 1, "navigateLastPage": 1, "firstPage": 1, "lastPage": 1 } }
看到没,springboot集成了这个插件就是这么的简单!
先看到了使用,我们再开看看,背后的故事吧:
建议大家看下这个博客:
http://blog.csdn.net/zl18310999566/article/details/54097273
重要提示:
- 只有紧跟在 PageHelper.startPage 方法后的第一个 MyBatis 的查询(select)方法会被分页。
- 请不要在系统中配置多个分页插件(使用 spring 时,mybatis-config.xml 和 Spring<bean> 配置方式,请选择其中一种,不要同时配置多个分页插件)。
- 对于带有 for update 的 sql,会抛出运行时异常,对于这样的 sql 建议手动分页,毕竟这样的 sql 需要重视。
- 由于嵌套结果方式会导致结果集被折叠,因此分页查询的结果在折叠后总数会减少,所以无法保证分页结果数量正确
相关文章
- SpringBoot启动方式讲解和部署war项目到tomcat9
- 补习系列(21)-SpringBoot初始化之7招式
- SpringBoot 如何生成接口文档
- SpringBoot集成Eureka导致返回结果由json变为xml解决方案
- springboot 前后端日期json格式化
- 【SpringBoot笔记27】SpringBoot集成ES数据库之操作index索引(创建、删除、获取)
- 【SpringBoot笔记25】SpringBoot框架集成PageHelper分页插件以及自定义分页工具类
- 【SpringBoot笔记08】SpringBoot框架集成JDBC以及JdbcTemplate的使用
- 【SpringBoot笔记09】SpringBoot集成MyBatis框架、MyBatis Plus框架
- 【SpringBoot系列】最详细demo- 集成MyBatis
- 【SpringBoot18】SpringBoot 调用外部接口的三种方式
- 补习系列(8)-springboot 单元测试之道
- Springboot集成Web service接口服务
- SpringBoot缓存技术整合SpringData Redis
- springboot 使用 freemarker 无法正常跳转的问题?
- springboot拦截器拦了静态资源css,js,png,jpeg,svg等等静态资源