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================");

    }

}

 

posted @ 2016-03-30 09:50  独孤黑狼  阅读(304)  评论(0编辑  收藏  举报