From 5bc904db9ae6ca87a16edcfb924bcf9e80b19309 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期二, 27 九月 2022 17:17:13 +0800 Subject: [PATCH] 1 --- src/main/java/com/lf/server/config/WebConfig.java | 26 ++++++++++++-------------- 1 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/lf/server/config/WebConfig.java b/src/main/java/com/lf/server/config/WebConfig.java index d56c4e6..a74cf90 100644 --- a/src/main/java/com/lf/server/config/WebConfig.java +++ b/src/main/java/com/lf/server/config/WebConfig.java @@ -3,20 +3,19 @@ import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.support.config.FastJsonConfig; import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.stereotype.Component; import org.springframework.util.AntPathMatcher; import org.springframework.web.servlet.config.annotation.*; -import java.util.ArrayList; +import java.nio.charset.Charset; import java.util.List; /** * WebConfig * @author WWW */ -@Configuration +@Component public class WebConfig extends WebMvcConfigurationSupport { /** * swagger鎺у埗 @@ -44,11 +43,11 @@ @Override protected void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") + .allowCredentials(true) .allowedOrigins("*") + .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") .allowedHeaders("*") - .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE") - .maxAge(3600) - .allowCredentials(true); + .maxAge(3600); } /** @@ -65,19 +64,18 @@ @Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter(); - FastJsonConfig fastJsonConfig = new FastJsonConfig(); - fastJsonConfig.setSerializerFeatures( + FastJsonConfig config = new FastJsonConfig(); + config.setSerializerFeatures( SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteMapNullValue, - SerializerFeature.WriteNullStringAsEmpty, + //SerializerFeature.WriteNullStringAsEmpty, + SerializerFeature.WriteNullNumberAsZero, SerializerFeature.WriteNullBooleanAsFalse); // 缁撴灉鏄惁鏍煎紡鍖�,榛樿涓篺alse //SerializerFeature.PrettyFormat); - List<MediaType> fastMediaTypes = new ArrayList<>(); - converter.setSupportedMediaTypes(fastMediaTypes); - - converter.setFastJsonConfig(fastJsonConfig); + converter.setFastJsonConfig(config); + converter.setDefaultCharset(Charset.forName("UTF-8")); converters.add(converter); } } -- Gitblit v1.9.3