content: package site.alanliang.geekblog.config;
  
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
  import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  import site.alanliang.geekblog.interceptor.WebInterceptor;
  
  /**
   * @Descriptin WebMvc配置
   * @Author AlanLiang
   * Date 2020/4/6 9:37
   * Version 1.0
   **/
  @Configuration
  public class WebMvcConfig implements WebMvcConfigurer {
  
      @Value("${file.path}")
      private String path;
  
      /**
       * 添加静态资源文件，外部可以直接访问地址
       *
       * @param registry
       */
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry registry) {
          registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
          registry.addResourceHandler("/file/**").addResourceLocations("file:" + path);
      }
  
      @Override
      public void addInterceptors(InterceptorRegistry registry) {
          registry.addInterceptor(new WebInterceptor())
                  .addPathPatterns("/admin/**")
                  .excludePathPatterns("/admin/login", "/admin/login.html", "/admin/captcha");
      }
  }
  