Commit 03a222a35722a68435614bbe0a6bc588056183d0
1 parent
09872bd0
还原long精度改造,导致了两个严重问题
1表单的日期字段,不能显示日期格式 2前端分页插件报错
Showing
2 changed files
with
22 additions
and
20 deletions
jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java
1 | package org.jeecg.config; | 1 | package org.jeecg.config; |
2 | 2 | ||
3 | -import com.fasterxml.jackson.databind.DeserializationFeature; | ||
4 | import com.fasterxml.jackson.databind.ObjectMapper; | 3 | import com.fasterxml.jackson.databind.ObjectMapper; |
5 | import com.fasterxml.jackson.databind.module.SimpleModule; | 4 | import com.fasterxml.jackson.databind.module.SimpleModule; |
6 | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | 5 | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; |
7 | import org.springframework.beans.factory.annotation.Value; | 6 | import org.springframework.beans.factory.annotation.Value; |
8 | import org.springframework.boot.actuate.trace.http.InMemoryHttpTraceRepository; | 7 | import org.springframework.boot.actuate.trace.http.InMemoryHttpTraceRepository; |
9 | -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
10 | import org.springframework.context.annotation.Bean; | 8 | import org.springframework.context.annotation.Bean; |
11 | import org.springframework.context.annotation.Conditional; | 9 | import org.springframework.context.annotation.Conditional; |
12 | import org.springframework.context.annotation.Configuration; | 10 | import org.springframework.context.annotation.Configuration; |
13 | -import org.springframework.context.annotation.Primary; | ||
14 | -import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; | 11 | +import org.springframework.http.converter.HttpMessageConverter; |
12 | +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | ||
15 | import org.springframework.web.cors.CorsConfiguration; | 13 | import org.springframework.web.cors.CorsConfiguration; |
16 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | 14 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; |
17 | import org.springframework.web.filter.CorsFilter; | 15 | import org.springframework.web.filter.CorsFilter; |
@@ -19,6 +17,8 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry | @@ -19,6 +17,8 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry | ||
19 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; | 17 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; |
20 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | 18 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
21 | 19 | ||
20 | +import java.util.List; | ||
21 | + | ||
22 | /** | 22 | /** |
23 | * Spring Boot 2.0 解决跨域问题 | 23 | * Spring Boot 2.0 解决跨域问题 |
24 | * | 24 | * |
@@ -71,24 +71,20 @@ public class WebMvcConfiguration implements WebMvcConfigurer { | @@ -71,24 +71,20 @@ public class WebMvcConfiguration implements WebMvcConfigurer { | ||
71 | return new CorsFilter(urlBasedCorsConfigurationSource); | 71 | return new CorsFilter(urlBasedCorsConfigurationSource); |
72 | } | 72 | } |
73 | 73 | ||
74 | - | ||
75 | /** | 74 | /** |
76 | - * 序列换成json时,将所有的long变成string | ||
77 | - * js中long过长精度丢失 | ||
78 | - */ | ||
79 | - @Bean | ||
80 | - @Primary | ||
81 | - @ConditionalOnMissingBean(ObjectMapper.class) | ||
82 | - 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(); | ||
83 | ObjectMapper objectMapper = new ObjectMapper(); | 81 | ObjectMapper objectMapper = new ObjectMapper(); |
84 | SimpleModule simpleModule = new SimpleModule(); | 82 | SimpleModule simpleModule = new SimpleModule(); |
85 | - //忽略在json字符串中存在,在java类中不存在字段,防止错误。 | ||
86 | - objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
87 | - objectMapper.configure(DeserializationFeature.READ_ENUMS_USING_TO_STRING, true); | ||
88 | simpleModule.addSerializer(Long.class, ToStringSerializer.instance); | 83 | simpleModule.addSerializer(Long.class, ToStringSerializer.instance); |
89 | simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); | 84 | simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); |
90 | objectMapper.registerModule(simpleModule); | 85 | objectMapper.registerModule(simpleModule); |
91 | - return objectMapper; | 86 | + jackson2HttpMessageConverter.setObjectMapper(objectMapper); |
87 | + converters.add(jackson2HttpMessageConverter); | ||
92 | } | 88 | } |
93 | 89 | ||
94 | /** | 90 | /** |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-gateway/src/main/java/org/jeecg/handler/MySwaggerResourceProvider.java
1 | package org.jeecg.handler; | 1 | package org.jeecg.handler; |
2 | 2 | ||
3 | -import lombok.extern.slf4j.Slf4j; | 3 | +import java.util.ArrayList; |
4 | +import java.util.HashSet; | ||
5 | +import java.util.List; | ||
6 | +import java.util.Set; | ||
7 | + | ||
4 | import org.springframework.beans.factory.annotation.Autowired; | 8 | import org.springframework.beans.factory.annotation.Autowired; |
5 | import org.springframework.beans.factory.annotation.Value; | 9 | import org.springframework.beans.factory.annotation.Value; |
6 | import org.springframework.cloud.gateway.route.RouteLocator; | 10 | import org.springframework.cloud.gateway.route.RouteLocator; |
11 | +import org.springframework.context.annotation.Primary; | ||
7 | import org.springframework.stereotype.Component; | 12 | import org.springframework.stereotype.Component; |
13 | + | ||
14 | +import lombok.extern.slf4j.Slf4j; | ||
8 | import springfox.documentation.swagger.web.SwaggerResource; | 15 | import springfox.documentation.swagger.web.SwaggerResource; |
9 | import springfox.documentation.swagger.web.SwaggerResourcesProvider; | 16 | import springfox.documentation.swagger.web.SwaggerResourcesProvider; |
10 | 17 | ||
11 | -import java.util.*; | ||
12 | - | ||
13 | /** | 18 | /** |
14 | * 聚合各个服务的swagger接口 | 19 | * 聚合各个服务的swagger接口 |
15 | */ | 20 | */ |
16 | @Component | 21 | @Component |
17 | @Slf4j | 22 | @Slf4j |
23 | +@Primary | ||
18 | public class MySwaggerResourceProvider implements SwaggerResourcesProvider { | 24 | public class MySwaggerResourceProvider implements SwaggerResourcesProvider { |
19 | /** | 25 | /** |
20 | * swagger2默认的url后缀 | 26 | * swagger2默认的url后缀 |
@@ -46,7 +52,7 @@ public class MySwaggerResourceProvider implements SwaggerResourcesProvider { | @@ -46,7 +52,7 @@ public class MySwaggerResourceProvider implements SwaggerResourcesProvider { | ||
46 | .filter(route -> !self.equals(route.getUri().getHost())) | 52 | .filter(route -> !self.equals(route.getUri().getHost())) |
47 | .subscribe(route -> routeHosts.add(route.getUri().getHost())); | 53 | .subscribe(route -> routeHosts.add(route.getUri().getHost())); |
48 | 54 | ||
49 | - // 记录已经添加过的server,存在同一个应用注册了多个服务在eureka上 | 55 | + // 记录已经添加过的server,存在同一个应用注册了多个服务在nacos上 |
50 | Set<String> dealed = new HashSet<>(); | 56 | Set<String> dealed = new HashSet<>(); |
51 | routeHosts.forEach(instance -> { | 57 | routeHosts.forEach(instance -> { |
52 | // 拼接url | 58 | // 拼接url |