自定义注解的实现其实就是通过动态代理或者aop的思想去实现,这里用的是aop的方法
引入aop的jar
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency>
在抒写 自定义注解;
这个需要注意的地方是target中的类型:如果你需要该注解用于类上,就使用type,
type表示的是用于类、枚举、接口上,method用于方法上
创建一个aspect类
这里需要注意类上的注解, 然而:@Around("@annotation(routingWith)") 中的around表示方法执行前执行,@annotation(routingWith)是指controller上标注的注解,传入的参数
ProceedingJoinPoint表示aop的切点也就是切点对应的方法,RoutingWith表示我们前面自己定义的注解对象,同时value是拿到controller上注解传入的参数