SpringBoot整合Mybatis-Plus分页失效的解决
作者:庞胖
本文主要介绍了SpringBoot整合Mybatis-Plus分页失效的解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
场景:项目整合mybatis-Plus分页失效,current一直是1,size一直是10,total属性一直是0,数据分页不准
先看官网给的示例:
解决方案是新建mybatis-Plus的配置文件:
package com.amc.config; import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; 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; import org.springframework.transaction.annotation.EnableTransactionManagement; /** * @Author: pangyq * @CreateTime: 2022-12-11 17:36 * @Description: mybatisPlus配置 * 针对于分页查询失效问题 * @Version: 1.0 */ @EnableTransactionManagement @MapperScan("com.amc.**.mapper") @Configuration public class MyBatisPlusConfig { @Bean public MybatisPlusInterceptor mybatisPlusInterceptor() { MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); PaginationInnerInterceptor innerInterceptor = new PaginationInnerInterceptor(); innerInterceptor.setDbType(DbType.MYSQL); innerInterceptor.setOverflow(true); interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor()); interceptor.addInnerInterceptor(innerInterceptor); return interceptor; } @Bean public ConfigurationCustomizer configurationCustomizer() { return mybatisConfiguration -> mybatisConfiguration.setUseGeneratedShortKey(false); } }
响应:
{ "code": "00", "msg": "成功", "data": { "records": [ { "userId": "1599928568143081472", "userName": "admin", "nickName": "张三", "userType": "00", "email": "23*****405@qq.com", "phoneNumber": "184****6521", "sex": "0", "avatar": "http://xxxx", "password": "uLRrSaBv+ERnSHOw9Yge9A==", "birthday": null, "townId": null, "townName": "", "countyId": null, "countyName": "", "provinceId": null, "provinceName": "", "cityName": "", "cityId": null, "detailAddress": "山东省济南市历下区", "status": "0", "delFlag": "0", "loginIp": "", "loginDate": null, "createBy": "", "createTime": "2022-12-06T00:47:50.000+0000", "updateBy": "", "updateTime": null, "remark": "这是注册用户测试", "tenantId": "-1", "revision": null } ], "total": 1, "size": 1, "current": 1, "orders": [], "optimizeCountSql": true, "hitCount": false, "countId": null, "maxLimit": null, "searchCount": true, "pages": 1 } }
至此,分页方案解决完毕!!!
到此这篇关于SpringBoot整合Mybatis-Plus分页失效的解决的文章就介绍到这了,更多相关SpringBoot Mybatis-Plus分页失效内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
您可能感兴趣的文章:
- springboot整合mybatis-plus 实现分页查询功能
- springboot整合mybatis-plus实现多表分页查询的示例代码
- oracle+mybatis-plus+springboot实现分页查询的实例
- springboot使用Mybatis-plus分页插件的案例详解
- SpringBoot结合mybatis-plus实现分页的项目实践
- SpringBoot整合mybatis-plus实现分页查询功能
- SpringBoot使用mybatis-plus分页查询无效的问题解决
- SpringBoot+MyBatis-Plus实现分页功能
- SpringBoot中使用MyBatis-Plus实现分页接口的详细教程
- SpringBoot+MyBatis-Plus实现分页的项目实践