控制器:
@PostMapping("api/postmethod")
public Response getResponse(@RequestParam String name, @RequestBody Object obj...){
....
}
方面:
@After("execution(* *(..))")
public void after(JoinPoint joinPoint){
...
}
如何在Aspect建议中获取请求uri->(“ api / postmethod”)?
以下代码将获得PostMapping路径
@Around("@annotation(postMapping) && within(com.aop.example.web.controller..*)")
public Object postMapping(ProceedingJoinPoint jp,PostMapping postMapping) throws Throwable {
System.out.println(Arrays.asList(postMapping.value()));
return jp.proceed();
}
说明:
切入点表达式@Around("@annotation(postMapping) && within(com.aop.example.web.controller..*)")
可以解释如下
@PostMapping
和]注释的方法>com.aop.example.web.controller
内的任何类中>可将参数传递给建议的文档参考here