当前位置:网站首页>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,解决办法
边栏推荐
- Qt项目中的日志库log4qt使用
- Adg5412fbruz-rl7 applies dual power analog switch and multiplexer IC
- SRE核心体系了解
- In C language, int a= 'R'
- PHY驱动调试之 --- MDIO/MDC接口22号和45号条款(一)
- LSA Type Explanation - lsa-5 (type 5 LSA - autonomous system external LSA) and lsa-4 (type 4 LSA - ASBR summary LSA) explanation
- Special training of C language array
- Volcano resource reservation feature
- Redis-01. First meet redis
- Rehabilitation type force deduction brush question notes D2
猜你喜欢

Mutual transformation between two-dimensional array and sparse array (sparse matrix)

Ros2 - configuration development environment (V)

代码中的英语全部

Ros2 - common command line (IV)

Qt项目中的日志库log4qt使用

. Net core stepping on the pit practice

ROS2——Service服务(九)

并发编程 — 死锁排查及处理

使用paping工具进行tcp端口连通性检测

Sum of two numbers, the numbers in the array are converted to decimal, added, and output inversely
随机推荐
6-3 find the table length of the linked table
mingling
6-2 sequence table operation set
Get class files and attributes by reflection
扫盲-以太网MII接口类型大全-MII、RMII、SMII、GMII、RGMII、SGMII、XGMII、XAUI、RXAUI
2. Addition and management of Oracle data files
new和malloc的区别
Ros2 - workspace (V)
'mongoexport 'is not an internal or external command, nor is it a runnable program or batch file.
*P++, (*p) + +, * (p++) differences
The route of wechat applet jumps again without triggering onload
UIO driven framework
Genesis builds a new generation of credit system
1. Create Oracle database manually
Utf8 encoding
Ros2 - ros2 vs. ros1 (II)
Ros2 topic (VIII)
Edge calculation data sorting
解读最早的草图-图像翻译工作SketchyGAN
C语言数组专题训练