当前位置:网站首页>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
边栏推荐
- kata container
- 【软件测试】04 -- 软件测试与软件开发
- SRE核心体系了解
- Mid 2022 documentary -- the experience of an ordinary person
- Literacy Ethernet MII interface types Daquan MII, RMII, smii, gmii, rgmii, sgmii, XGMII, XAUI, rxaui
- ROS2——node节点(七)
- Ros2 - ros2 vs. ros1 (II)
- How to answer when you encounter a jet on CSDN?
- 数据库Mysql全部
- 能量守恒和打造能量缺口
猜你喜欢

namespace

并发编程 — 如何中断/停止一个运行中的线程?

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

代码中的英语全部

一文揭开,测试外包公司的真实情况

ROS2——工作空间(五)

Database mysql all

7. Oracle table structure

UTC, GPS time and Tai

LSA Type Explanation - detailed explanation of lsa-2 (type II LSA network LSA) and lsa-3 (type III LSA network Summary LSA)
随机推荐
Technology blog learning website
SD_CMD_RECEIVE_SHIFT_REGISTER
Rehabilitation type force deduction brush question notes D3
你心目中的数据分析 Top 1 选 Pandas 还是选 SQL?
扫盲-以太网MII接口类型大全-MII、RMII、SMII、GMII、RGMII、SGMII、XGMII、XAUI、RXAUI
PHY驱动调试之 --- MDIO/MDC接口22号和45号条款(一)
How to answer when you encounter a jet on CSDN?
Integer to 8-bit binary explanation (including positive and negative numbers) scope of application -127~+127
ROS2——初识ROS2(一)
【软件测试】06 -- 软件测试的基本流程
基于Cortex-M3、M4的GPIO口位带操作宏定义(可总线输入输出,可用于STM32、ADuCM4050等)
Qt项目中的日志库log4qt使用
Mipi interface, DVP interface and CSI interface of camera
ROS2——topic话题(八)
【软件测试】05 -- 软件测试的原则
二分查找(折半查找)
LSA Type Explanation - lsa-1 [type 1 LSA - router LSA] detailed explanation
What is linting
testing framework
A brief introduction to heading/pitch/roll and omega/phi/kappa