zoukankan      html  css  js  c++  java
  • springMVC拦截器的使用

    1、新建一个config包和一个配置拦截类MyInterceptor,并继承接口HandlerInterceptor.

    快捷键(Ctrl + o)实现该接口的三个方法:

    public class MyInterceptor implements HandlerInterceptor {
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    
            System.out.println("================处理前=============");
            return false;
        }
        //拦截日志
        public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
            System.out.println("=================处理后==============");
        }
        //拦截日志
        public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
            System.out.println("=================清理==============");
        }
    }

    其中:

    ① preHandle方法在前端URL请求前处理,默认返回false表示禁止所有通过url访问的请求,true表示允许。

    ② postHandle方法在前端URL请求中处理,一般默认使用日志。afterCompletion类似。

    2、在spring类路径配置文件applicationContext.xml中追加配置类的信息

    <mvc:interceptors>
            <mvc:interceptor>
                <!--过滤哪个请求-->
                <mvc:mapping path="/**"/>
                <!--由谁来过滤-->
                <bean class="com.meng.config.MyInterceptor"/>
            </mvc:interceptor>
        </mvc:interceptors>
  • 相关阅读:
    innerHTML,outerHTML,innerText,outerText
    vue生命周期
    vue属性监听
    vue计算属性(通过计算得来的属性)
    express脚手架的安装,以及ejs的语法
    mongoose的基本操作方法
    vue的基本指令
    MongoDB
    五分钟让你拥有自己的聊天室
    带你了解世界最先进的手势识别技术 -- 微软,凌感,Leap...
  • 原文地址:https://www.cnblogs.com/Meng2113/p/13503575.html
Copyright © 2011-2022 走看看