fix(mp): 注册 MyBatis-Plus 分页拦截器,修复 page() 返回 total=0
CI/CD Deploy (Admin) / 构建后端镜像并部署 (push) Successful in 1m25s
CI/CD Deploy (Admin) / 构建后端镜像并部署 (push) Successful in 1m25s
- 新增 MybatisPlusConfig 注册 PaginationInnerInterceptor - 修复分页查询只填充 records、total/pages 恒为 0 的问题
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package com.freedom.admin.config;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* MyBatis-Plus 分页插件配置
|
||||
*
|
||||
* @author zhangjiaxun
|
||||
* @description 注册分页拦截器后,Service.page() 才会执行 count 并返回正确的 total/pages,
|
||||
* 否则仅填充 records 而 total 恒为 0
|
||||
*/
|
||||
@Configuration
|
||||
public class MybatisPlusConfig {
|
||||
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user