content: package com.moti.config;
  
  import com.moti.component.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.boot.web.servlet.MultipartConfigFactory;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.http.HttpStatus;
  import org.springframework.util.unit.DataSize;
  import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
  import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  
  import javax.servlet.MultipartConfigElement;
  
  @Configuration
  public class MvcConfig implements WebMvcConfigurer, ErrorPageRegistrar {
      @Bean
      public MultipartConfigElement multipartConfigElement() {
          MultipartConfigFactory factory = new MultipartConfigFactory();
          //文件最大
          factory.setMaxFileSize(DataSize.parse("1024000KB"));
          /// 设置总上传数据总大小
          factory.setMaxRequestSize(DataSize.parse("1024000KB"));
          return factory.createMultipartConfig();
      }
  
      /**
       * @Description 注册视图控制器
       * @Author xw
       * @Date 15:11 2020/2/26
       * @Param [registry]
       * @return void
       **/
      @Override
      public void addViewControllers(ViewControllerRegistry registry) {
          registry.addViewController("/").setViewName("index");
          registry.addViewController("/temp-file").setViewName("temp-file");
          registry.addViewController("/error400Page").setViewName("error/400");
          registry.addViewController("/error401Page").setViewName("error/401");
          registry.addViewController("/error404Page").setViewName("error/404");
          registry.addViewController("/error500Page").setViewName("error/500");
      }
  
      /**
       * @Description  注册登录拦截器 addPathPatterns() -> 拦截的请求  excludePathPatterns -> 不拦截的请求
       * @Author xw
       * @Date 15:10 2020/2/26
       * @Param [registry]
       * @return void
       **/
      @Override
      public void addInterceptors(InterceptorRegistry registry) {
          registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**")
                  .excludePathPatterns(
                          "/","/temp-file","/error400Page","/error401Page","/error404Page","/error500Page","/uploadTempFile","/admin","/sendCode","/loginByQQ","/login","/register","/file/share","/connection",
                          "/asserts/**","/**/*.css", "/**/*.js", "/**/*.png ", "/**/*.jpg"
                          ,"/**/*.jpeg","/**/*.gif", "/**/fonts/*", "/**/*.svg");
      }
      
      /**
       * @Description 配置错误页面
       * @Author xw
       * @Date 13:27 2020/3/11
       * @Param [registry]
       * @return void
       **/
      @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);
      }
  }
  