当前位置:网站首页>IPage can display data normally, but total is always equal to 0
IPage can display data normally, but total is always equal to 0
2022-07-05 07:01:00 【Emmmmm_ one】
Problem description : The code uses Mybatis-Plus Automatic paging of ,getRecords() correct , however getTotal() Always equal to 0
No problem with code logic , So look for Mybatis-Plus Configuration problems
Try the best way :
1. Whether the configuration class is added @Configuration
2. The statistical SQL Automatically optimized , Inaccurate statistics lead to ---> close Mybatis-Plus Automatic optimization of
Page<?> page = new Page<>(currentPage, size); // Open paging
page.setOptimizeCountSql(false); // close mybatisPlus Automatic optimization of
This method is inefficient , You can write it yourself count sql
page.setSearchCount(false);
page.setTotal(mapper.listCount(sql));
Reference article : MyBatis-Plus Of IPage Pagination total Incorrect question
MybatisPlus Automatic paging ,total Inaccurate questions
3. Set the type of database
PaginationInnerInterceptor page = new PaginationInnerInterceptor();
page.setDbType(DbType.MYSQL);
return page;
4. Check mybatis-plus-boot-starter edition
3.4.0 The version has an update to this part , If it is an old version upgrade , Paging failure will occur , meanwhile idea Will prompt PaginationInterceptor obsolete , The new version uses MybatisPlusInterceptor
In the end, I put PaginationInnerInterceptor Instead of MybatisPlusInterceptor solve
The successful code is as follows :
@Configuration
public class MybatisPlusConfig {
/**
* Implement paging configuration
* @return
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor()); // Register optimistic lock plugin
interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); // Paging plug-ins
return interceptor;
}
}
This part of the code comes from :Page Pagination records There's data , however total=0, terms of settlement
边栏推荐
- Preemption of CFS scheduling
- Ros2 - configuration development environment (V)
- Ret2xx---- common CTF template proposition in PWN
- ROS2——ROS2对比ROS1(二)
- 基于FPGA的一维卷积神经网络CNN的实现(八)激活层实现
- Volcano 资源预留特性
- Integer to 8-bit binary explanation (including positive and negative numbers) scope of application -127~+127
- LSA Type Explanation - detailed explanation of lsa-2 (type II LSA network LSA) and lsa-3 (type III LSA network Summary LSA)
- Get class files and attributes by reflection
- LSA Type Explanation - lsa-5 (type 5 LSA - autonomous system external LSA) and lsa-4 (type 4 LSA - ASBR summary LSA) explanation
猜你喜欢
随机推荐
6-4 search by serial number of linked list
new和malloc的区别
Volcano 资源预留特性
Preemption of CFS scheduling
testing framework
Cookie、Session、JWT、token四者间的区别与联系
6-2 sequence table operation set
A brief introduction to heading/pitch/roll and omega/phi/kappa
Rehabilitation type force deduction brush question notes D2
睿智的目标检测59——Pytorch Focal loss详解与在YoloV4当中的实现
C语言数组专题训练
2022年中纪实 -- 一个普通人的经历
Mipi interface, DVP interface and CSI interface of camera
NVM Downloading npm version 6.7.0... Error
Edge calculation data sorting
ROS2——常用命令行(四)
Marvell 88E1515 PHY loopback模式测试
GDB code debugging
SD_CMD_SEND_SHIFT_REGISTER
7. Oracle table structure