• 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/**");//对应的不拦截的请求
        }
    }
  • 相关阅读:
    如何寻找第二大轮廓
    基础_模型迁移_CBIR_augmentation
    基础_模型迁移_CBIR_augmentation
    MQ通道配置
    WebSphere MQ 入门指南
    P2P小贷网站业务数据流程分享
    发博客后自动同步摘要到新浪微博
    Linux Shell脚本攻略 读书笔记
    Linux Shell 文本处理工具集锦
    Berkeley 四种产品如何选择?
  • 原文地址:https://www.cnblogs.com/nongzihong/p/11232350.html
Copyright © 2020-2023  润新知