HandlerInterceptorAdapter和HandlerInterceptor
1. 简介
要自定一个拦截器,要门继承 HandlerInterceptorAdapter类 或者实现 HandlerInterceptor接口,第一种方法已经过期。
2.
public class LoginInterceptor implements HandlerInterceptor { //Intercept the execution of a handler. Called after HandlerMapping determined //an appropriate handler object, but before HandlerAdapter invokes the handler. @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (request.getSession().getAttribute("user")==null){ response.sendRedirect("/admin"); return false; } return true; } //Intercept the execution of a handler. Called after HandlerAdapter actual // ly invoked the handler, but before the DispatcherServlet renders the view. @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { } // Callback after completion of request processing @Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { } }TRANSLATE with
| Arabic | Hebrew | Polish |
| Bulgarian | Hindi | Portuguese |
| Catalan | Hmong Daw | Romanian |
| Chinese Simplified | Hungarian | Russian |
| Chinese Traditional | Indonesian | Slovak |
| Czech | Italian | Slovenian |
| Danish | Japanese | Spanish |
| Dutch | Klingon | Swedish |
| English | Korean | Thai |
| Estonian | Latvian | Turkish |
| Finnish | Lithuanian | Ukrainian |
| French | Malay | Urdu |
| German | Maltese | Vietnamese |
| Greek | Norwegian | Welsh |
| Haitian Creole | Persian |