content: package com.moti.config;
  
  import com.moti.interceptor.LoginHandlerInterceptor;
  import org.springframework.boot.web.server.ErrorPage;
  import org.springframework.boot.web.server.ErrorPageRegistrar;
  import org.springframework.boot.web.server.ErrorPageRegistry;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.http.HttpStatus;
  import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
  import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  
  /**
   * @ClassName: MvcConfig
   * @Description: 配置MVC相关信息
   * @author: 莫提
   * @Date 18:58 2020/8/30
   * @Version: 1.0
   **/
  @Configuration
  public class MvcConfig implements WebMvcConfigurer, ErrorPageRegistrar {
  
      /**
       * 注册视图控制器
       */
      @Override
      public void addViewControllers(ViewControllerRegistry registry) {
          // 注册登录页面
          registry.addViewController("/admin-login").setViewName("login");
          // 注册错误页面
          registry.addViewController("/error400Page").setViewName("error/400");
          registry.addViewController("/error401Page").setViewName("error/401");
          registry.addViewController("/error404Page").setViewName("error/404");
          registry.addViewController("/error500Page").setViewName("error/500");
      }
  
      /**
       * 配置错误页面
       */
      @Override
      public void registerErrorPages(ErrorPageRegistry registry) {
          ErrorPage error400Page = new ErrorPage(HttpStatus.BAD_REQUEST, "/error400Page");
          ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, "/error401Page");
          ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/error404Page");
          ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error500Page");
          registry.addErrorPages(error400Page,error401Page,error404Page,error500Page);
      }
  
      /**
       * 注册登录拦截器
       */
      @Override
      public void addInterceptors(InterceptorRegistry registry) {
          registry.addInterceptor(new LoginHandlerInterceptor())
                  // 拦截的请求
                  .addPathPatterns("/**")
                  // 不拦截的请求（放行）
                  .excludePathPatterns(
                          "/","/index","/admin","/admin/test",
                          "/admin-login","/login","/loginByQQ","/connection",
                          "/error400Page","/error401Page","/error404Page","/error500Page",
                          "/article","/getMoreArticles","/search","/addComment"
                          ,"/asserts/**","/**/*.css", "/**/*.js", "/**/*.png ", "/**/*.jpg"
                          ,"/**/*.jpeg","/**/*.gif", "/**/fonts/*", "/**/*.svg");
      }
  }
  