我正在学习Spring AOP。我想为这个方法添加一个after方法:
@RequestMapping(method = RequestMethod.POST)
public String precessRegistration(@Valid User user, BindingResult result, ModelMap modelMap){
....
}
由于此方法有三个参数,因此我的方面如下所示:
@Pointcut("execution( * com.springapp.mvc.view.RegisterController." +
"precessRegistration(com.springapp.mvc.domain.beans.User," +
"org.springframework.validation.BindingResult," +
"org.springframework.ui.ModelMap))" +
"&& args(user, result, model))")
public void postRegistration(User user, BindingResult result, ModelMap model){}
@AfterReturning("postRegistration(user, result, model)")
public void keepRecordOfLogin(User user, BindingResult result, ModelMap model){
logger.info("User [" + user.getUsername() + "] logged in.");
}
我列出了让这个方面运行的所有参数。有没有办法让我不需要列出所有的参数?
答案 0 :(得分:0)
列出args是可以说执行切入点的选项。你可以参考下面的链接了解AOP弹簧。
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html
或简而言之,您可以使用以下内容供您参考..
@Pointcut("execution(public * *(..))")
private void anyPublicOperation() {}
@Pointcut("within(com.xyz.someapp.trading..*)")
private void inTrading() {}
@Pointcut("anyPublicOperation() && inTrading()")
private void tradingOperation() {}