注解本质上就是一个aop。现将一个简易的注解实现方式举例如下:
1,声明注解
@Retention(RetentionPolicy.RUNTIME)
public @interface CheckInput {
}
2,实现注解的aop拦截
@Pointcut("@annotation(com.mw.anotation.CheckInput)")
public void checkControllerInput3() {
}
@Before(value = "checkControllerInput3()")
public void checkInput(JoinPoint joinPoint) throws Throwable {}
3,在controller上打上注解
@CheckInput
@PostMapping("/query")
public RestPriceQueryOutput queryPrice(@RequestBody RestPriceQueryInput restPriceQueryInput){
return priceService.queryPrice(restPriceQueryInput);
}
Java简易注解实现方式举例
博客介绍了Java中注解的简易实现方式。注解本质上是一种AOP,具体步骤为声明注解、实现注解的AOP拦截,最后在controller上打上注解。

被折叠的 条评论
为什么被折叠?



