springmvc 拦截器

来源:互联网 发布:iso9126软件质量模型 编辑:程序博客网 时间:2024/06/15 19:16

拦截器实现

/*
 * AllInterceptor.java    1.0  2017-8-18
 *
 * 沈阳成林健康科技有限公司
 * 
 */


package com.zr.interceptor;


import org.springframework.ui.ModelMap;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.context.request.WebRequestInterceptor;


/**
 * [关于类内容的描述]
 * 
 * @author mnt115
 * @version 1.0
 * 
 *          变更履历:
 *          v1.0 2017-8-18 mnt115 初版
 */
public class AllInterceptor implements WebRequestInterceptor {


    @Override
    public void afterCompletion(WebRequest arg0, Exception arg1) throws Exception {
        // TODO Auto-generated method stub
        System.out.println("AllInterceptor after");
    }


    @Override
    public void postHandle(WebRequest arg0, ModelMap arg1) throws Exception {
        // TODO Auto-generated method stub
        System.out.println("AllInterceptor in");
    }


    @Override
    public void preHandle(WebRequest arg0) throws Exception {
        // TODO Auto-generated method stub
        System.out.println("AllInterceptor befor");
    }


}


xml 文件配置 支持mvc标签

  xmlns:mvc="http://www.springframework.org/schema/mvc"  

 http://www.springframework.org/schema/mvc  
          http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd

使用mvc标签配置拦截器

<mvc:interceptors>  
   <mvc:interceptor>  
       <mvc:mapping path="/users/login.do"/>  
       <!-- 定义在mvc:interceptor下面的表示是对特定的请求才进行拦截的 -->  
       <bean class="com.zr.interceptor.LoginInterceptor"/>  
   </mvc:interceptor>
</mvc:interceptors>


原创粉丝点击