当前位置:网站首页>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
边栏推荐
猜你喜欢
睿智的目标检测59——Pytorch Focal loss详解与在YoloV4当中的实现
ROS2——ROS2对比ROS1(二)
inux摄像头(mipi接口)简要说明
Ros2 - Service Service (IX)
Volcano 资源预留特性
Rehabilitation type force deduction brush question notes D2
ROS2——配置开发环境(五)
PHY drive commissioning - phy controller drive (II)
SD_CMD_RECEIVE_SHIFT_REGISTER
1. Create Oracle database manually
随机推荐
1290_FreeRTOS中prvTaskIsTaskSuspended()接口实现分析
MySQL (UDF authorization)
Interpretation of the earliest sketches - image translation work sketchygan
一文揭开,测试外包公司的真实情况
Some classic recursion problems
Cloud native related technology learning
Rehabilitation type force deduction brush question notes D2
ROS2——常用命令行(四)
Literacy Ethernet MII interface types Daquan MII, RMII, smii, gmii, rgmii, sgmii, XGMII, XAUI, rxaui
Use the Paping tool to detect TCP port connectivity
在本地搭建一个微服务集群环境,学习自动化部署
ethtool 原理介绍和解决网卡丢包排查思路(附ethtool源码下载)
睿智的目标检测59——Pytorch Focal loss详解与在YoloV4当中的实现
About vscode, "code unreachable" will be displayed when calling sendline series functions with pwntools“
window navicat连接阿里云服务器mysql步骤及常见问题
Vant Weapp SwipeCell設置多個按鈕
postmessage通信
网易To B,柔外刚中
Ros2 - common command line (IV)
并发编程 — 如何中断/停止一个运行中的线程?