<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency>
package com.shanhy.sboot.aop;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Aspect // FOR AOP
@Order(-99) // 控制多个Aspect的执行顺序,越小越先执行
@Component
public class TestAspect {
@Before("@annotation(test)")// 拦截被TestAnnotation注解的方法;如果你需要拦截指定package指定规则名称的方法,可以使用表达式execution(...),具体百度一下资料一大堆
public void beforeTest(JoinPoint point, TestAnnotation test) throws Throwable {
System.out.println("beforeTest:" + test.name());
}
@After("@annotation(test)")
public void afterTest(JoinPoint point, TestAnnotation test) {
System.out.println("afterTest:" + test.name());
}
}
@RestController
@RequestMapping("/test")
public class TestController {
@TestAnnotation(name="abc")
@RequestMapping("/show")
public String show() {
return "OK";
}
@RequestMapping("/show2")
public String show2() {
return "OK2";
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有