import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Aspect
@Component
@Slf4j
public class TraderAspect2 {
/**
* 切入点表达式,拦截com.weiwen.provider.web.trade.UserTraderController类下的所有方法
*/
@Pointcut("execution(* com.weiwen.provider.web.trade.UserTraderController.*(..))")
public void user() {
}
/**
* 切入点表达式,拦截方法上有@Auth注解的所有方法
*/
@Pointcut("@annotation(com.weiwen.provider.utils.Auth)")
public void userAuth() {
}
/**
* @param point
* @return
* @throws Throwable
*/
@Around("userAuth()")
public Object around(ProceedingJoinPoint pjp) throws Throwable {
Object[] args = pjp.getArgs(); //获取目标方法参数
boolean flag=false;
/**
* 如果flag为true就执行目标方法
*/
if (flag == true) {
pjp.proceed(); //执行目标方法
} else {
System.out.println("直接返回");
return null;
}
}
Spring AOP环绕通知
最新推荐文章于 2024-04-11 21:47:20 发布