Spring-MVC拦截器

   

  1. <!-- 此配置拦截一切请求-->
  2.     <mvc:interceptors>
  3.         <bean id="myInterceptor" class="cn.tri.interceptor.MyInterceptor"></bean>
  4.     </mvc:interceptors>

       

  5. <!-- 此配置拦截所配置路径请求à

       

      <!-- <mvc:interceptors>
            <mvc:interceptor>
                <mvc:mapping path="/aaa"/>  拦截path  
                <mvc:exclude-mapping path="testUpload"/> 不拦截path
                <bean id="myInterceptor" class="cn.tri.interceptor.MyInterceptor"></bean>
            </mvc:interceptor>
        </mvc:interceptors> -->

   

   

  •     //实现handlerInterceptor 接口
  • public class MyInterceptor implements HandlerInterceptor{
  •     
  •         @Override
  •         public boolean preHandle(HttpServletRequest request,
  •                 HttpServletResponse response, Object handler) throws Exception {
  •             System.out.println("prehandle拦截请求");
  •             return true;
  • //true 全部通过   false全部拦截
  • }
  •     
  •         @Override
  •         public void postHandle(HttpServletRequest request,
  •                 HttpServletResponse response, Object handler,
  •                 ModelAndView modelAndView) throws Exception {
  •             System.out.println("postHandle");
  •         }
  •     
  •         @Override
  •         public void afterCompletion(HttpServletRequest request,
  •                 HttpServletResponse response, Object handler, Exception ex)
  •                 throws Exception {
  •                 System.out.println("afterCompletion 渲染请求 ");        }
  •     
  •     }

   

   

   

   

posted @ 2020-10-17 14:53  黑质白章  阅读(92)  评论(0编辑  收藏  举报