ganzi-api/inventory-gov/src/main/java/com/rzyc/advice/PageAspect.java
2022-09-16 15:07:17 +08:00

35 lines
1.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.rzyc.advice;
import com.github.pagehelper.PageHelper;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import java.lang.reflect.Field;
/**
* @Author jilin
* @Date 2021/11/09 11:57
* 分页aop
* 注解写在mapper上aop代理方式需为jdk代理cglib代理无法aop mapper
**/
@Aspect
@Component
public class PageAspect {
@Pointcut("@annotation(com.rzyc.advice.PageOperation)execution(* com.rzyc..*.*(..))")
public void page() {}
@Before("page()")
public void pageOperation(JoinPoint joinPoint) throws IllegalAccessException, NoSuchFieldException {
Object[] args = joinPoint.getArgs();
Class clazz = args[0].getClass();
Field page = clazz.getDeclaredField("page");
page.setAccessible(true);
Field pageSize = clazz.getDeclaredField("pageSize");
pageSize.setAccessible(true);
PageHelper.startPage((Integer) page.get(args[0]),(Integer) pageSize.get(args[0]));
}
}