Spring Boot以及Feign使用Java 8中LocalDate等时间日期类的问题解决

This commit is contained in:
zhaiyongchao
2018-03-13 09:13:32 +08:00
parent c610db6afc
commit a2d33c0d1e
4 changed files with 124 additions and 0 deletions
+44
View File
@@ -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;
}
}
@@ -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;
}