@Aspect 使之成为切面类
@Pointcut("execution(public * com.tunynet.soft.modules.controller.LinkController.*(..))") 定义切点
@Around是可以同时在所拦截方法的前后执行一段逻辑。
@Before 是在所拦截方法执行之前执行一段逻辑
@After 目标方法执行之后执行以下方法体的内容,不管是否发生异常
@AfterThrowing目标方法发生(异常)的时候执行以下代码
@AfterReturning目标方法(正常)执行完毕时执行以下代码
===============================
@Aspect
@Component 把切面类加入到IOC容器中
@Slf4j
public class WebSecurityAspect {
/**
* 切面检查权限
*
* @param joinPoint
* @return
* @throws Throwable
*/
@Around(value = "@annotation(AmnTest)") #仅在添加@AmnTest的地方进行切面
public Object authoritiesCheck(ProceedingJoinPoint joinPoint) throws Throwable {
return joinPoint.proceed();
}
//在哪切
@Pointcut("execution(public * com.tunynet.soft.modules.controller.LinkController.*(..))")
public void test() {
}
@Around(value = "test()") #使用提前定义的切点
public Object amnTest(ProceedingJoinPoint joinPoint) throws Throwable {
//------------------------方法执行之前
//访问方法的名字
System.out.println(joinPoint.getSignature().getName());
System.out.println(joinPoint.getSignature().getModifiers());
//访问类的完整路径
System.out.println(joinPoint.getSignature().getDeclaringTypeName());
//开始执行方法
Object proceed = joinPoint.proceed();
//------------------------方法执行之后
System.out.println("after");
return proceed;
}
}