Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
yangxiujun
/
paidan_demo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 1508e3a0
authored
Jul 05, 2023
by
丁伟峰
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature-dingwf-0715' into develop
2 parents
bf4e68f1
8e1def95
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
1 deletions
project-order/src/main/java/com/dituhui/pea/order/config/JacksonConfig.java
project-order/src/main/java/com/dituhui/pea/order/config/JacksonConfig.java
View file @
1508e3a
...
...
@@ -2,17 +2,37 @@ package com.dituhui.pea.order.config;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
;
import
com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer
;
import
com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer
;
import
com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer
;
import
com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer
;
import
com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer
;
import
com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.LocalTime
;
import
java.time.format.DateTimeFormatter
;
@Configuration
public
class
JacksonConfig
{
@Bean
public
ObjectMapper
objectMapper
()
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
objectMapper
.
registerModule
(
new
JavaTimeModule
());
// 日期和时间格式化
JavaTimeModule
javaTimeModule
=
new
JavaTimeModule
();
javaTimeModule
.
addSerializer
(
LocalDateTime
.
class
,
new
LocalDateTimeSerializer
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
)));
javaTimeModule
.
addSerializer
(
LocalDate
.
class
,
new
LocalDateSerializer
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd"
)));
javaTimeModule
.
addSerializer
(
LocalTime
.
class
,
new
LocalTimeSerializer
(
DateTimeFormatter
.
ofPattern
(
"HH:mm:ss"
)));
javaTimeModule
.
addDeserializer
(
LocalDateTime
.
class
,
new
LocalDateTimeDeserializer
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
)));
javaTimeModule
.
addDeserializer
(
LocalDate
.
class
,
new
LocalDateDeserializer
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd"
)));
javaTimeModule
.
addDeserializer
(
LocalTime
.
class
,
new
LocalTimeDeserializer
(
DateTimeFormatter
.
ofPattern
(
"HH:mm:ss"
)));
objectMapper
.
registerModule
(
javaTimeModule
);
return
objectMapper
;
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment