Java-拦截器(结合业务)202005

 

工作几年,对拦截器没有啥理解,之前写过如同过眼云烟,现年纪越来越大,记性越来越差,特此记录。

相关知识博文:

Spring MVC 拦截器 interceptor 详解

https://www.cnblogs.com/Shunia123/p/10669273.html

 

Q:servlet和mvc区别?


 

正文

本次业务:需要给几个页面增加一个公共的拦截器


 

我想起来bip_api(mvc项目 非maven项目)里有Bip_Api项目 有 token拦截器处理,回顾一下:

 Bip项目的配置文件:

 代码截取:

     <mvc:interceptors>  
        <!-- 多个拦截器,顺序执行 -->  
        <mvc:interceptor>  
           <mvc:mapping path="/api/**" /> 
           <bean class="com.sapinfo.interceptor.TokenValidatorInterceptor">
           </bean>  
        </mvc:interceptor> 
     </mvc:interceptors>

 


 

MVC的 参考代码(谢谢於~MiniAppInterceptor):

特别的,(MVC项目)新建拦截器后需要在这个xml里面配置下, 这样启动才会生效。(文&图源:於)

 

假如,就以MiniAppInterceptor为例:

contacts-servlet.xml中是这样写的,意思是当访问所有@RequestMapping中以/miniapp/integralimall打头的 contoller里的方法时,请求都会先进MiniAppInterceptor这个拦截器。

        <mvc:interceptor>
            <mvc:mapping path="/miniapp/**" />
            <mvc:mapping path="/integralimall/**" />
            <bean class="sapinfo.pub.interceptor.MiniAppInterceptor">
            </bean>
        </mvc:interceptor>

 

posted @ 2020-05-27 17:22  淘来的星湖  阅读(193)  评论(0)    收藏  举报