Commit 1b75a5c09d71f6e408c2aeed52f25ec07f9365d5
1 parent
aa5f1900
修改有问题,还原代码 【Long转json精度丢失的配置 未生效】
Showing
1 changed file
with
12 additions
and
12 deletions
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; | @@ -5,12 +5,11 @@ import com.fasterxml.jackson.databind.module.SimpleModule; | ||
5 | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | 5 | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; |
6 | import org.springframework.beans.factory.annotation.Value; | 6 | import org.springframework.beans.factory.annotation.Value; |
7 | import org.springframework.boot.actuate.trace.http.InMemoryHttpTraceRepository; | 7 | import org.springframework.boot.actuate.trace.http.InMemoryHttpTraceRepository; |
8 | -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
9 | import org.springframework.context.annotation.Bean; | 8 | import org.springframework.context.annotation.Bean; |
10 | import org.springframework.context.annotation.Conditional; | 9 | import org.springframework.context.annotation.Conditional; |
11 | import org.springframework.context.annotation.Configuration; | 10 | import org.springframework.context.annotation.Configuration; |
12 | -import org.springframework.context.annotation.Primary; | ||
13 | -import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; | 11 | +import org.springframework.http.converter.HttpMessageConverter; |
12 | +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | ||
14 | import org.springframework.web.cors.CorsConfiguration; | 13 | import org.springframework.web.cors.CorsConfiguration; |
15 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | 14 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; |
16 | import org.springframework.web.filter.CorsFilter; | 15 | import org.springframework.web.filter.CorsFilter; |
@@ -18,6 +17,8 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry | @@ -18,6 +17,8 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry | ||
18 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; | 17 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; |
19 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | 18 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
20 | 19 | ||
20 | +import java.util.List; | ||
21 | + | ||
21 | /** | 22 | /** |
22 | * Spring Boot 2.0 解决跨域问题 | 23 | * Spring Boot 2.0 解决跨域问题 |
23 | * | 24 | * |
@@ -70,21 +71,20 @@ public class WebMvcConfiguration implements WebMvcConfigurer { | @@ -70,21 +71,20 @@ public class WebMvcConfiguration implements WebMvcConfigurer { | ||
70 | return new CorsFilter(urlBasedCorsConfigurationSource); | 71 | return new CorsFilter(urlBasedCorsConfigurationSource); |
71 | } | 72 | } |
72 | 73 | ||
73 | - | ||
74 | /** | 74 | /** |
75 | - * 序列换成json时,将所有的long变成string | ||
76 | - * js中long过长精度丢失 | ||
77 | - */ | ||
78 | - @Bean | ||
79 | - @Primary | ||
80 | - @ConditionalOnMissingBean(ObjectMapper.class) | ||
81 | - public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) { | 75 | + * 添加Long转json精度丢失的配置 |
76 | + * @Return: void | ||
77 | + */ | ||
78 | + @Override | ||
79 | + public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { | ||
80 | + MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter(); | ||
82 | ObjectMapper objectMapper = new ObjectMapper(); | 81 | ObjectMapper objectMapper = new ObjectMapper(); |
83 | SimpleModule simpleModule = new SimpleModule(); | 82 | SimpleModule simpleModule = new SimpleModule(); |
84 | simpleModule.addSerializer(Long.class, ToStringSerializer.instance); | 83 | simpleModule.addSerializer(Long.class, ToStringSerializer.instance); |
85 | simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); | 84 | simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); |
86 | objectMapper.registerModule(simpleModule); | 85 | objectMapper.registerModule(simpleModule); |
87 | - return objectMapper; | 86 | + jackson2HttpMessageConverter.setObjectMapper(objectMapper); |
87 | + converters.add(jackson2HttpMessageConverter); | ||
88 | } | 88 | } |
89 | 89 | ||
90 | /** | 90 | /** |