public class MyHandlerInterceptor extends HandlerInterceptorAdapter {
/*
* 进入请求前调用
*/
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) throws Exception {
System.out.println("-----preHandle");
return super.preHandle(request, response, handler);
}
/*
* 请求处理完毕后调用
*/
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response,
Object handler, ModelAndView modelAndView) throws Exception {
System.out.println("-----postHandle");
super.postHandle(request, response, handler, modelAndView);
}
/*
* 全部处理完毕后调用
*/
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
Object handler, Exception ex) throws Exception {
System.out.println("-----afterCompletion");
super.afterCompletion(request, response, handler, ex);
}
}
log结果:
-----preHandle
-----postHandle
-----afterCompletion