Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jeecg-boot
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenjunxiong
jeecg-boot
Commits
1998867c
Commit
1998867c
authored
Sep 14, 2021
by
zhangdaiscott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Long转json精度丢失的配置 未生效
parent
a3512048
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
12 deletions
+16
-12
jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java
+16
-12
No files found.
jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java
View file @
1998867c
package
org
.
jeecg
.
config
;
package
org
.
jeecg
.
config
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.module.SimpleModule
;
import
com.fasterxml.jackson.databind.module.SimpleModule
;
import
com.fasterxml.jackson.databind.ser.std.ToStringSerializer
;
import
com.fasterxml.jackson.databind.ser.std.ToStringSerializer
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.actuate.trace.http.InMemoryHttpTraceRepository
;
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.Bean
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.
http.converter.HttpMessageConverter
;
import
org.springframework.
context.annotation.Primary
;
import
org.springframework.http.converter.json.
MappingJackson2HttpMessageConvert
er
;
import
org.springframework.http.converter.json.
Jackson2ObjectMapperBuild
er
;
import
org.springframework.web.cors.CorsConfiguration
;
import
org.springframework.web.cors.CorsConfiguration
;
import
org.springframework.web.cors.UrlBasedCorsConfigurationSource
;
import
org.springframework.web.cors.UrlBasedCorsConfigurationSource
;
import
org.springframework.web.filter.CorsFilter
;
import
org.springframework.web.filter.CorsFilter
;
...
@@ -17,8 +19,6 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
...
@@ -17,8 +19,6 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
import
org.springframework.web.servlet.config.annotation.ViewControllerRegistry
;
import
org.springframework.web.servlet.config.annotation.ViewControllerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
java.util.List
;
/**
/**
* Spring Boot 2.0 解决跨域问题
* Spring Boot 2.0 解决跨域问题
*
*
...
@@ -71,20 +71,24 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
...
@@ -71,20 +71,24 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
return
new
CorsFilter
(
urlBasedCorsConfigurationSource
);
return
new
CorsFilter
(
urlBasedCorsConfigurationSource
);
}
}
/**
/**
* 添加Long转json精度丢失的配置
* 序列换成json时,将所有的long变成string
* @Return: void
* js中long过长精度丢失
*/
*/
@Override
@Bean
public
void
configureMessageConverters
(
List
<
HttpMessageConverter
<?>>
converters
)
{
@Primary
MappingJackson2HttpMessageConverter
jackson2HttpMessageConverter
=
new
MappingJackson2HttpMessageConverter
();
@ConditionalOnMissingBean
(
ObjectMapper
.
class
)
public
ObjectMapper
jacksonObjectMapper
(
Jackson2ObjectMapperBuilder
builder
)
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
ObjectMapper
objectMapper
=
new
ObjectMapper
();
SimpleModule
simpleModule
=
new
SimpleModule
();
SimpleModule
simpleModule
=
new
SimpleModule
();
//忽略在json字符串中存在,在java类中不存在字段,防止错误。
objectMapper
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
objectMapper
.
configure
(
DeserializationFeature
.
READ_ENUMS_USING_TO_STRING
,
true
);
simpleModule
.
addSerializer
(
Long
.
class
,
ToStringSerializer
.
instance
);
simpleModule
.
addSerializer
(
Long
.
class
,
ToStringSerializer
.
instance
);
simpleModule
.
addSerializer
(
Long
.
TYPE
,
ToStringSerializer
.
instance
);
simpleModule
.
addSerializer
(
Long
.
TYPE
,
ToStringSerializer
.
instance
);
objectMapper
.
registerModule
(
simpleModule
);
objectMapper
.
registerModule
(
simpleModule
);
jackson2HttpMessageConverter
.
setObjectMapper
(
objectMapper
);
return
objectMapper
;
converters
.
add
(
jackson2HttpMessageConverter
);
}
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment