Skip to content

Commit

Permalink
Spring Boot以及Feign使用Java 8中LocalDate等时间日期类的问题解决
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc87112 committed Mar 13, 2018
1 parent c610db6 commit a2d33c0
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
63 changes: 63 additions & 0 deletions Chapter3-1-7/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.didispace</groupId>
<artifactId>Chapter3-1-7</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>Chapter3-1-7</name>
<description>Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.20</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>

</project>
44 changes: 44 additions & 0 deletions Chapter3-1-7/src/main/java/com/didispace/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.didispace;

import com.didispace.dto.UserDto;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
* @author 程序猿DD
* @version 1.0.0
* @blog http://blog.didispace.com
*/
@SpringBootApplication
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

@RestController
class HelloController {

@PostMapping("/user")
public UserDto user(@RequestBody UserDto userDto) throws Exception {
return userDto;
}

}

@Bean
public ObjectMapper serializingObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
objectMapper.registerModule(new JavaTimeModule());
return objectMapper;
}

}
17 changes: 17 additions & 0 deletions Chapter3-1-7/src/main/java/com/didispace/dto/UserDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.didispace.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

@NoArgsConstructor
@AllArgsConstructor
@Data
public class UserDto {

private String userName;
private LocalDate birthday;

}
Empty file.

0 comments on commit a2d33c0

Please sign in to comment.