WebMvcConfig.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package com.izouma.awesomeAdmin.config;
  2. import org.springframework.beans.factory.annotation.Value;
  3. import org.springframework.context.annotation.Bean;
  4. import org.springframework.context.annotation.Configuration;
  5. import org.springframework.web.servlet.config.annotation.CorsRegistry;
  6. import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
  7. import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  8. @Configuration
  9. public class WebMvcConfig implements WebMvcConfigurer {
  10. @Value("${storage.local_path}")
  11. private String localPath;
  12. @Override
  13. public void addResourceHandlers(ResourceHandlerRegistry registry) {
  14. // registry.addResourceHandler("/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
  15. // registry.addResourceHandler("webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
  16. registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
  17. registry.addResourceHandler("/admin/**").addResourceLocations("classpath:/static/admin/");
  18. registry.addResourceHandler("/files/**").addResourceLocations("file:" + localPath);
  19. registry.addResourceHandler("/MP_verify*").addResourceLocations("classpath:/");
  20. }
  21. // @Bean
  22. // public Docket createApi() {
  23. // return new Docket(DocumentationType.SWAGGER_2)
  24. // .apiInfo(new ApiInfoBuilder()
  25. // .title("接口文档")
  26. // .version("1.0.0")
  27. // .termsOfServiceUrl("#")
  28. // .description("接口文档")
  29. // .build())
  30. // .select()
  31. // .apis(RequestHandlerSelectors.basePackage("com.izouma.awesomeAdmin.web"))
  32. // .paths(PathSelectors.any())
  33. // .build();
  34. // }
  35. // @Bean
  36. // public MappingJackson2HttpMessageConverter getMappingJackson2HttpMessageConverter() {
  37. // MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
  38. // //设置日期格式
  39. // ObjectMapper objectMapper = new ObjectMapper();
  40. // objectMapper.setDateFormat(CustomDateFormat.instance);
  41. // objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
  42. // mappingJackson2HttpMessageConverter.setObjectMapper(objectMapper);
  43. // //设置中文编码格式
  44. // List<MediaType> list = new ArrayList<>();
  45. // list.add(MediaType.APPLICATION_JSON_UTF8);
  46. // mappingJackson2HttpMessageConverter.setSupportedMediaTypes(list);
  47. // return mappingJackson2HttpMessageConverter;
  48. // }
  49. // @Override
  50. // public void addFormatters(FormatterRegistry registry) {
  51. // DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
  52. // registrar.setUseIsoFormat(true);
  53. // registrar.registerFormatters(registry);
  54. // }
  55. @Override
  56. public void addCorsMappings(CorsRegistry registry) {
  57. registry.addMapping("/**")
  58. .allowedHeaders("*")
  59. .allowCredentials(true)
  60. .allowedMethods("HEAD", "GET", "PUT", "POST", "DELETE", "PATCH")
  61. .allowedOrigins("http://10.5.23.169")
  62. .exposedHeaders("Content-Disposition");
  63. }
  64. }