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/**");//对应的不拦截的请求
        }
    }
  • 相关阅读:
    python库--pandas--Series.str--字符串处理
    前端--jstree--异步加载数据
    python库--flask--创建嵌套蓝图
    Git--生成公钥和私钥并添加gitlab访问权限
    es查询--请求body
    python生成时间序列(date_range)
    golang使用组合完成伪继承
    golang interface类型的动态绑定
    ruby环境安装草稿
    openfire
  • 原文地址:https://www.cnblogs.com/nongzihong/p/11232350.html
Copyright © 2011-2022 走看看