From a35120486560f593927ba0a57969bcb5037c296c Mon Sep 17 00:00:00 2001 From: zhangdaiscott Date: Tue, 14 Sep 2021 17:48:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E6=97=B6=E8=BF=98=E5=8E=9F=E4=BB=A3?= =?UTF-8?q?=E7=A0=81,=E6=94=B9=E7=9A=84=E6=9C=89=E9=97=AE=E9=A2=98=20[Long?= =?UTF-8?q?=E8=BD=ACjson=E7=B2=BE=E5=BA=A6=E4=B8=A2=E5=A4=B1=E7=9A=84?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=20=E6=9C=AA=E7=94=9F=E6=95=88]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/config/WebMvcConfiguration.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java b/jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java index f7fe9bce..9b2689d5 100644 --- a/jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java +++ b/jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java @@ -5,12 +5,11 @@ import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.actuate.trace.http.InMemoryHttpTraceRepository; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; @@ -18,6 +17,8 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import java.util.List; + /** * Spring Boot 2.0 解决跨域问题 * @@ -70,21 +71,20 @@ public class WebMvcConfiguration implements WebMvcConfigurer { return new CorsFilter(urlBasedCorsConfigurationSource); } - /** - * 序列换成json时,将所有的long变成string - * js中long过长精度丢失 - */ - @Bean - @Primary - @ConditionalOnMissingBean(ObjectMapper.class) - public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) { + * 添加Long转json精度丢失的配置 + * @Return: void + */ + @Override + public void configureMessageConverters(List> converters) { + MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter(); ObjectMapper objectMapper = new ObjectMapper(); SimpleModule simpleModule = new SimpleModule(); simpleModule.addSerializer(Long.class, ToStringSerializer.instance); simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); objectMapper.registerModule(simpleModule); - return objectMapper; + jackson2HttpMessageConverter.setObjectMapper(objectMapper); + converters.add(jackson2HttpMessageConverter); } /**