当前位置:网站首页>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
边栏推荐
- Ros2 - workspace (V)
- kata container
- Spinningup drawing curve
- 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 - configuration development environment (V)
- Ros2 - first acquaintance with ros2 (I)
- LSA Type Explanation - detailed explanation of lsa-2 (type II LSA network LSA) and lsa-3 (type III LSA network Summary LSA)
- Database mysql all
- Utf8 encoding
猜你喜欢
随机推荐
Mid 2022 documentary -- the experience of an ordinary person
Edge calculation data sorting
[Chongqing Guangdong education] National Open University 2018 autumn 0702-22t contemporary Chinese political system reference questions
LSA Type Explanation - lsa-5 (type 5 LSA - autonomous system external LSA) and lsa-4 (type 4 LSA - ASBR summary LSA) explanation
Orin 安装CUDA环境
【软件测试】02 -- 软件缺陷管理
ROS2——配置开发环境(五)
GDB code debugging
二分查找(折半查找)
MySQL (UDF authorization)
Cookie、Session、JWT、token四者间的区别与联系
. Net core stepping on the pit practice
6-3 find the table length of the linked table
扫盲-以太网MII接口类型大全-MII、RMII、SMII、GMII、RGMII、SGMII、XGMII、XAUI、RXAUI
Architecture
使用paping工具进行tcp端口连通性检测
Lexin interview process
What is linting
1. Create Oracle database manually
Ros2 - workspace (V)