でSPRING 3.0を使用しています私のアプリケーションの要件とコード
@Controller
public class ConsoleUserManagementController{
@RequestMapping(value = CONSOLE_NAMESPACE + "/account/changePassword.do", method = RequestMethod.GET)
@doLog(true)
public ModelAndView showChangePasswordPage() {
String returnView = USERMANAGEMENT_NAMESPACE + "/account/ChangePassword";
ModelAndView mavChangePassword = new ModelAndView(returnView);
LogUtils.logInfo("Getting Change Password service prerequisit attributes");
mavChangePassword.getModelMap().put("passwordModel", new PasswordModel());
return mavChangePassword;
}
}
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// here I want the controller method name(i.e showChangePasswordPage()
// for /account/changePassword.do url) to be called and that method annotation
// (i.e doLog()) so that by viewing annotation , I can manage whether for that
// particular controller method, whether to enable logging or not.
}
を見てください。アスペクトを使用して、すべてのコントローラメソッドに対して一般的なインターセプタを作成しようとする可能性があります。
aspectを使用すると、joinpointメソッド名に簡単にアクセスできます。
あなたはあなたの側面または使用の内側にリクエストオブジェクトを挿入することができます
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
あなたのアドバイスの方法からそれを取得するには。例えば
:あなたはそれを次のようにやって
@Around("execution (* com.yourpackages.controllers.*.*(..)) && @annotation(org.springframework.web.bind.annotation.RequestMapping)")
public Object doSomething(ProceedingJoinPoint pjp){
pjp.getSignature().getDeclaringType().getName();
}
チェックしましたか? –