zoukankan      html  css  js  c++  java
  • Spring Boot 7.拦截器

    package com.example.springbootstudy;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.web.servlet.HandlerInterceptor;
    import org.springframework.web.servlet.ModelAndView;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class UserInterceptor implements HandlerInterceptor {
    
        private static final Logger logger = LoggerFactory.getLogger(UserInterceptor.class);
    
        @Override
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
            logger.debug("preHandle");
    //        throw new Exception("preHandle Exception");
            return true;
        }
    
        @Override
        public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
            logger.debug("postHandle");
    //        throw new Exception("postHandle Exception");
        }
    
    
        @Override
        public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
            logger.debug("afterCompletion");
        }
    }
    package com.example.springbootstudy;
    
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    
    @Configuration
    public class AppMvcConfig implements WebMvcConfigurer {
    
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new UserInterceptor()).addPathPatterns("/**");
        }
    }
  • 相关阅读:
    socket http tcp udp ip 协议
    docker启动报错iptables failed: -重建docker0网络恢复
    python3处理json数据
    nginx添加认证
    安装nginx和nginx-gridfs和mongodb
    Centos7下CPU内存等资源监控
    linux 中 iptables关于ping的问题
    python3和pip3安装和问题解决
    Centos7下安装zabbix 3.0.19
    ansible学习网站
  • 原文地址:https://www.cnblogs.com/hbolin/p/10671694.html
Copyright © 2011-2022 走看看