zoukankan      html  css  js  c++  java
  • Springboot 注册拦截器

    拦截器

    创建myInterceptor类

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.springframework.web.servlet.HandlerInterceptor;
    import org.springframework.web.servlet.ModelAndView;
    
    public class MyInterceptor1 implements HandlerInterceptor {
    
      @Override
      public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
          throws Exception {
        System.out.println("MyInterceptor >>> preHandle");
        return true;
      }
    
      @Override
      public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
          ModelAndView modelAndView) throws Exception {
        System.out.println("MyInterceptor >>> postHandle");
      }
    
      @Override
      public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
          Object handler, Exception ex) throws Exception {
        System.out.println("MyInterceptor >>> afterHandle");
      }
    }
    

    配置拦截器

    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.servlet.config.annotation.CorsRegistry;
    import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    
    @Configuration
    public class MyWebMvcConfig implements WebMvcConfigurer {
    
      @Override
      public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyInterceptor1()).addPathPatterns("/**")
            .excludePathPatterns("/hello");
      }
    }
    
  • 相关阅读:
    封装好的AFN网络请求框架和MBProgress
    iOS定时器的使用
    iOS去除导航栏和tabbar的1px横线
    移动端加解密
    改变字符串中部分字符传的字体大小和颜色
    关于NSLog
    ipad开发:二维码扫描,摄像头旋转角度问题解决办法
    iOS-图文表并茂,手把手教你GCD
    计算富文本的高度
    jsp打印
  • 原文地址:https://www.cnblogs.com/Draymonder/p/11824906.html
Copyright © 2011-2022 走看看