zoukankan      html  css  js  c++  java
  • Springboot配置拦截器

    public class LoginInterceptor implements HandlerInterceptor {
    
        private static final Logger log = LoggerFactory.getLogger(LoginInterceptor.class);
    
        /**
         * 进入controller层之前拦截请求
         *
         * @param httpServletRequest
         * @param httpServletResponse
         * @param o
         * @return
         * @throws Exception
         */
        @Override
        public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
          log。info("---------------开始进入地址拦截器-------------------")return true;
        }
        //访问controller之后 访问视图之前被调用
        @Override
        public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
            log.info("--------------处理请求完成后视图渲染之前的处理操作---------------");
        }
        //访问视图之后被调用
        @Override
        public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
            log.info("---------------视图渲染之后的操作-------------------------0");
        }
    
    }
    /*
    拦截器配置类
     */
    @Configuration
    public class WebAppConfig extends WebMvcConfigurerAdapter {
    
        // 多个拦截器组成一个拦截器链
        // addPathPatterns 用于添加拦截规则
        // excludePathPatterns 用户排除拦截
    
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new LoginInterceptor())//添加拦截器
                    .addPathPatterns("/**") //拦截所有请求
                    .excludePathPatterns("/UserCon/**", "/Doctor/**", "/SMS/**");//对应的不拦截的请求
        }
    }
  • 相关阅读:
    相关博客
    读写锁
    vccode配置c++ 编译环境
    windows下内存检测工具
    定时器堆的实现的方法
    关于tcp send的再次思考
    关于一个socket在阻塞模式下是否还可以使用的实验
    windows下对socket的send和recv的超时设置,并附一个简洁明了的socket简单demo
    对于vector中高效删除中间元素的技巧
    ubuntu下后台服务的管理
  • 原文地址:https://www.cnblogs.com/nongzihong/p/11232350.html
Copyright © 2011-2022 走看看