您好,我正在尝试使用 aop 将日志记录应用到我的应用程序。此时,我可以使用此切入点将建议应用于应用程序中的所有 PostMapping 方法。
@Pointcut("@annotation(org.springframework.web.bind.annotation.PostMapping)")
public void postAction() {
}
这是建议
@Before("postAction()")
public void beforePost(JoinPoint joinPoint) {
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder
.getRequestAttributes())).getRequest();
String name = request.getParameter("firstName");
logger.info(name);
}
我不希望这个。我希望建议仅适用于处理用户对象的 PostMappings,我猜这指的是处理 postmappings 的 3 个控制器。在这种情况下,我的包结构是这样的。
src>main>java>com>example>myApp>controller>(the 3 classes i want are here:EmployeeController,StudentController,UserController)
我怎么做这个切入点
@Pointcut("@annotation(org.springframework.web.bind.annotation.PostMapping)")
只适用于以上3类?