爱程序网

HandlerInterceptor拦截器

来源: 阅读:

原码:

public interface HandlerInterceptor {

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

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

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

}

使用方法如:

public class ActionLogHandlerInterceptor implements HandlerInterceptor {

public boolean preHandle(HttpServletRequest request,
            HttpServletResponse response, Object handler) throws Exception {
       
   log.debug("==============执行顺序: 1、preHandle================");   

  return true;

}

 

@Override
    public void postHandle(HttpServletRequest request,
            HttpServletResponse response, Object handler,
            ModelAndView modelAndView) throws Exception {
        log.debug("==============执行顺序: 2、postHandle================");

    }

    @Override
    public void afterCompletion(HttpServletRequest request,
            HttpServletResponse response, Object handler, Exception ex)
            throws Exception {
        log.debug("==============执行顺序: 3、afterCompletion================");

    }

}

 

关于爱程序网 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助