Spring MVC 拦截器HandlerInterceptor(一)

HandlerInterceptor 接口:

进入 Handler方法之前执行
比如身份认证,如果认证通过表示当前用户没有登陆,需要此方法拦截不再向下执行

boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception;

  

进入Handler方法之后,返回modelAndView之前执行
应用场景从modelAndView出发:将公用的模型数据(比如菜单导航)在这里传到视图,也可以在这里统一指定视图

void postHandle(
			HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
			throws Exception;

执行Handler完成执行此方法 

应用场景:统一异常处理,统一日志处理

void afterCompletion(
			HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception;

  

原文地址:https://www.cnblogs.com/fanBlog/p/9597486.html