使用mvc:interceptors标签来声明需要加入到SpringMVC拦截器链中的拦截器

Xml代码   收藏代码
  1. <mvc:interceptors>  
  2.     <!-- 使用bean定义一个Interceptor,直接定义在mvc:interceptors根下面的Interceptor将拦截所有的请求 -->  
  3.     <bean class="com.host.app.web.interceptor.AllInterceptor"/>  
  4.     <mvc:interceptor>  
  5.         <mvc:mapping path="/test/number.do"/>  
  6.         <!-- 定义在mvc:interceptor下面的表示是对特定的请求才进行拦截的 -->  
  7.         <bean class="com.host.app.web.interceptor.LoginInterceptor"/>  
  8.     </mvc:interceptor>  
  9. </mvc:interceptors>  

          由上面的示例可以看出可以利用mvc:interceptors标签声明一系列的拦截器,然后它们就可以形成一个拦截器链,拦截器的执行顺序是按声明的先后顺序执行的,先声明的拦截器中的preHandle方法会先执行,然而它的postHandle方法和afterCompletion方法却会后执行。

          在mvc:interceptors标签下声明interceptor主要有两种方式:

        (1)直接定义一个Interceptor实现类的bean对象。使用这种方式声明的Interceptor拦截器将会对所有的请求进行拦截。

        (2)使用mvc:interceptor标签进行声明。使用这种方式进行声明的Interceptor可以通过mvc:mapping子标签来定义需要进行拦截的请求路径。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值