Skip to content

Commit a2d33c0

Browse files
committed
Spring Boot以及Feign使用Java 8中LocalDate等时间日期类的问题解决
1 parent c610db6 commit a2d33c0

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

Chapter3-1-7/pom.xml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.didispace</groupId>
7+
<artifactId>Chapter3-1-7</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>Chapter3-1-7</name>
12+
<description>Spring Boot</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.10.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-test</artifactId>
30+
<scope>test</scope>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-web</artifactId>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>com.fasterxml.jackson.datatype</groupId>
40+
<artifactId>jackson-datatype-jsr310</artifactId>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>org.projectlombok</groupId>
45+
<artifactId>lombok</artifactId>
46+
<version>1.16.20</version>
47+
</dependency>
48+
49+
</dependencies>
50+
51+
<build>
52+
<plugins>
53+
<plugin>
54+
<groupId>org.springframework.boot</groupId>
55+
<artifactId>spring-boot-maven-plugin</artifactId>
56+
<configuration>
57+
<fork>true</fork>
58+
</configuration>
59+
</plugin>
60+
</plugins>
61+
</build>
62+
63+
</project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.didispace;
2+
3+
import com.didispace.dto.UserDto;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import com.fasterxml.jackson.databind.SerializationFeature;
6+
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
7+
import org.springframework.boot.SpringApplication;
8+
import org.springframework.boot.autoconfigure.SpringBootApplication;
9+
import org.springframework.context.annotation.Bean;
10+
import org.springframework.web.bind.annotation.PostMapping;
11+
import org.springframework.web.bind.annotation.RequestBody;
12+
import org.springframework.web.bind.annotation.RestController;
13+
14+
/**
15+
* @author 程序猿DD
16+
* @version 1.0.0
17+
* @blog http://blog.didispace.com
18+
*/
19+
@SpringBootApplication
20+
public class Application {
21+
22+
public static void main(String[] args) {
23+
SpringApplication.run(Application.class, args);
24+
}
25+
26+
@RestController
27+
class HelloController {
28+
29+
@PostMapping("/user")
30+
public UserDto user(@RequestBody UserDto userDto) throws Exception {
31+
return userDto;
32+
}
33+
34+
}
35+
36+
@Bean
37+
public ObjectMapper serializingObjectMapper() {
38+
ObjectMapper objectMapper = new ObjectMapper();
39+
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
40+
objectMapper.registerModule(new JavaTimeModule());
41+
return objectMapper;
42+
}
43+
44+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.didispace.dto;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
import java.time.LocalDate;
8+
9+
@NoArgsConstructor
10+
@AllArgsConstructor
11+
@Data
12+
public class UserDto {
13+
14+
private String userName;
15+
private LocalDate birthday;
16+
17+
}

Chapter3-1-7/src/main/resources/application.properties

Whitespace-only changes.

0 commit comments

Comments
 (0)