Spring Boot以及Feign使用Java 8中LocalDate等时间日期类的问题解决
This commit is contained in:
@@ -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;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user