• springmvc拦截器和概念,配置!!!


    用于拦截请求,过滤后再拦截

    实现HandlerInterceptor接口

    配置拦截器

    package cn.zys.lanjieqi;
    
    
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.springframework.web.servlet.HandlerInterceptor;
    import org.springframework.web.servlet.ModelAndView;
    
    
    public class MyZhujieqi implements HandlerInterceptor{
        //在请求处理方法之前执行
        //如果返回true 执行下一个拦截器
        //如果返回false 就不执行下一个
        @Override
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
                throws Exception {
            // TODO Auto-generated method stub
            System.out.println("处理前~~");
            return true;
        }
        
        
        //在请求处理方法之后执行
        @Override
        public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
                ModelAndView modelAndView) throws Exception {
            // TODO Auto-generated method stub
            System.out.println("处理后~~");
            HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
        }
        
        
        //DispatcherServlet 处理后执行    --适合做一些清理工作
        @Override
        public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
                throws Exception {
            // TODO Auto-generated method stub
            HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
        }
        
    }

    配置mvc.xml

    <!-- 拦截器的配置 -->
        <mvc:interceptors>
        <!-- 配置一个拦截器 -->
            <mvc:interceptor>
            <!-- /**此路径下的所有子路径 -->
                <mvc:mapping path="/**"/>
                <bean class="cn.zys.lanjieqi.MyZhujieqi"></bean>
            </mvc:interceptor>
        </mvc:interceptors>
  • 相关阅读:
    Codeforces VK Cup 2015 A.And Yet Another Bracket Sequence(后缀数组+平衡树+字符串)
    Tensorflow框架初尝试————搭建卷积神经网络做MNIST问题
    TopCoder代码格式模板
    TopCoder[SRM513 DIV 1]:PerfectMemory(500)
    TopCoder[SRM513 DIV 1]:Reflections(1000)
    LCT模板
    FWT模板
    BZOJ2752:[HAOI2012]高速公路(road)
    BZOJ3332:旧试题
    BZOJ3171:[TJOI2013]循环格
  • 原文地址:https://www.cnblogs.com/xiaozhang666/p/11655211.html
Copyright © 2020-2023  润新知