当前位置:网站首页>IPage能正常显示数据,但是total一直等于0
IPage能正常显示数据,但是total一直等于0
2022-07-05 06:51:00 【Emmmmm_1】
问题描述:代码中使用Mybatis-Plus的自动分页,getRecords()正确,但是getTotal()一直等于0
代码逻辑没问题,所以找Mybatis-Plus配置上的问题
尝试的方法:
1. 配置类上是否加了@Configuration
2. 统计的SQL被自动优化了,导致统计结果不准确--->关闭Mybatis-Plus的自动优化
Page<?> page = new Page<>(currentPage, size); // 开启分页
page.setOptimizeCountSql(false); // 关闭mybatisPlus的自动优化这样的方法效率较低,可以自己写count sql
page.setSearchCount(false);
page.setTotal(mapper.listCount(sql));参考文章: MyBatis-Plus的IPage分页total不正确问题
3. 设置数据库的类型
PaginationInnerInterceptor page = new PaginationInnerInterceptor();
page.setDbType(DbType.MYSQL);
return page;4. 检查mybatis-plus-boot-starter版本
3.4.0版本对此部分有更新,如果是旧版本升级,会出现分页失效问题,同时idea会提示PaginationInterceptor过时,新版本改用了MybatisPlusInterceptor

最终是把PaginationInnerInterceptor换成了MybatisPlusInterceptor解决
成功的代码如下:
@Configuration
public class MybatisPlusConfig {
/**
* 实现分页配置
* @return
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor()); // 注册乐观锁插件
interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); // 分页插件
return interceptor;
}
}这部分代码来源:Page分页records有数据,但是total=0,解决办法
边栏推荐
- The problem of Chinese garbled code in the vscode output box can be solved once for life
- Ros2 - ros2 vs. ros1 (II)
- Ros2 - configuration development environment (V)
- 基于FPGA的一维卷积神经网络CNN的实现(八)激活层实现
- Ros2 - node (VII)
- Orin 两种刷机方式
- 微信小程序路由再次跳轉不觸發onload
- ethtool 原理介绍和解决网卡丢包排查思路(附ethtool源码下载)
- Technology blog learning website
- ROS2——node节点(七)
猜你喜欢
随机推荐
Redis-01. First meet redis
Get class files and attributes by reflection
ROS2——node节点(七)
Sum of two numbers, the numbers in the array are converted to decimal, added, and output inversely
Vant weave swipecell sets multiple buttons
全局变量和静态变量的初始化
Dameng database all
Mutual transformation between two-dimensional array and sparse array (sparse matrix)
Cloud native related technology learning
Xavier CPU & GPU high load power consumption test
The differences and connections among cookies, sessions, JWT, and tokens
Ros2 - common command line (IV)
VLAN experiment
ROS2——常用命令行(四)
NVM Downloading npm version 6.7.0... Error
Marvell 88e1515 PHY loopback mode test
Use ffmpeg to rotate, flip up and down, and flip horizontally
Architecture
SOC_SD_CMD_FSM
ethtool 原理介绍和解决网卡丢包排查思路(附ethtool源码下载)









