分页总数量为 -1 的情况2
This commit is contained in:
@@ -1,15 +1,7 @@
|
||||
package com.czg.config;
|
||||
|
||||
import com.mybatisflex.core.audit.AuditManager;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
@@ -29,50 +21,4 @@ public class MybatisFlexConfig {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理 Spring 容器管理的 Page Bean
|
||||
*/
|
||||
@Bean
|
||||
public BeanPostProcessor pageBeanPostProcessor() {
|
||||
return new BeanPostProcessor() {
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(@NotNull Object bean, @NotNull String beanName) throws BeansException {
|
||||
if (bean instanceof Page<?> page) {
|
||||
resetPageDefaultValue(page);
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* AOP 拦截所有 Page 实例的构造方法,重置初始值
|
||||
* 覆盖手动 new Page() 的场景
|
||||
*/
|
||||
@Aspect
|
||||
public static class PageConstructorAspect {
|
||||
|
||||
// 切入点:匹配 Page 类的所有构造方法执行后
|
||||
@Pointcut("execution(com.mybatisflex.core.pagination.Page+.new(..))")
|
||||
public void pageConstructorPointcut() {}
|
||||
|
||||
// 构造方法执行后重置值
|
||||
@AfterReturning(pointcut = "pageConstructorPointcut()", returning = "page")
|
||||
public void afterPageConstruct(Page<?> page) {
|
||||
resetPageDefaultValue(page);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用方法:重置 Page 初始值为 0
|
||||
*/
|
||||
private static void resetPageDefaultValue(Page<?> page) {
|
||||
if (page.getTotalPage() == -1) {
|
||||
page.setTotalPage(0);
|
||||
}
|
||||
if (page.getTotalRow() == -1) {
|
||||
page.setTotalRow(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user