|
@@ -1,9 +1,15 @@
|
|
|
package com.izouma.nineth.config;
|
|
package com.izouma.nineth.config;
|
|
|
|
|
|
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
+import com.fasterxml.jackson.databind.module.SimpleModule;
|
|
|
|
|
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
+import org.springframework.http.converter.HttpMessageConverter;
|
|
|
|
|
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
|
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
@@ -13,12 +19,17 @@ import springfox.documentation.builders.RequestHandlerSelectors;
|
|
|
import springfox.documentation.spi.DocumentationType;
|
|
import springfox.documentation.spi.DocumentationType;
|
|
|
import springfox.documentation.spring.web.plugins.Docket;
|
|
import springfox.documentation.spring.web.plugins.Docket;
|
|
|
|
|
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
@Configuration
|
|
@Configuration
|
|
|
@EnableConfigurationProperties(GeneralProperties.class)
|
|
@EnableConfigurationProperties(GeneralProperties.class)
|
|
|
public class WebMvcConfig implements WebMvcConfigurer {
|
|
public class WebMvcConfig implements WebMvcConfigurer {
|
|
|
@Value("${storage.local_path}")
|
|
@Value("${storage.local_path}")
|
|
|
private String localPath;
|
|
private String localPath;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
|
// registry.addResourceHandler("/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
|
|
// registry.addResourceHandler("/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
|
|
@@ -33,17 +44,31 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
|
|
public Docket createApi() {
|
|
public Docket createApi() {
|
|
|
return new Docket(DocumentationType.SWAGGER_2)
|
|
return new Docket(DocumentationType.SWAGGER_2)
|
|
|
.apiInfo(new ApiInfoBuilder()
|
|
.apiInfo(new ApiInfoBuilder()
|
|
|
- .title("接口文档")
|
|
|
|
|
- .version("1.0.0")
|
|
|
|
|
- .termsOfServiceUrl("#")
|
|
|
|
|
- .description("接口文档")
|
|
|
|
|
- .build())
|
|
|
|
|
|
|
+ .title("接口文档")
|
|
|
|
|
+ .version("1.0.0")
|
|
|
|
|
+ .termsOfServiceUrl("#")
|
|
|
|
|
+ .description("接口文档")
|
|
|
|
|
+ .build())
|
|
|
.select()
|
|
.select()
|
|
|
.apis(RequestHandlerSelectors.basePackage("com.izouma.nineth.web"))
|
|
.apis(RequestHandlerSelectors.basePackage("com.izouma.nineth.web"))
|
|
|
.paths(PathSelectors.any())
|
|
.paths(PathSelectors.any())
|
|
|
.build();
|
|
.build();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
|
|
|
|
+ converters.stream().filter(converter -> converter instanceof MappingJackson2HttpMessageConverter)
|
|
|
|
|
+ .forEach(converter -> {
|
|
|
|
|
+ ObjectMapper objectMapper = ((MappingJackson2HttpMessageConverter) converter).getObjectMapper();
|
|
|
|
|
+ SimpleModule simpleModule = new SimpleModule();
|
|
|
|
|
+ simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
|
|
|
|
|
+ simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
|
|
|
|
|
+ objectMapper.registerModule(simpleModule);
|
|
|
|
|
+ ((MappingJackson2HttpMessageConverter) converter).setObjectMapper(objectMapper);
|
|
|
|
|
+ });
|
|
|
|
|
+ System.out.println(converters);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// @Bean
|
|
// @Bean
|
|
|
// public MappingJackson2HttpMessageConverter getMappingJackson2HttpMessageConverter() {
|
|
// public MappingJackson2HttpMessageConverter getMappingJackson2HttpMessageConverter() {
|
|
|
// MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
|
|
// MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
|