diff --git a/Chapter3-1-7/pom.xml b/Chapter3-1-7/pom.xml new file mode 100644 index 0000000..660637b --- /dev/null +++ b/Chapter3-1-7/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + + com.didispace + Chapter3-1-7 + 1.0.0 + jar + + Chapter3-1-7 + Spring Boot + + + org.springframework.boot + spring-boot-starter-parent + 1.5.10.RELEASE + + + + + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.springframework.boot + spring-boot-starter-web + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + + org.projectlombok + lombok + 1.16.20 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + + \ No newline at end of file diff --git a/Chapter3-1-7/src/main/java/com/didispace/Application.java b/Chapter3-1-7/src/main/java/com/didispace/Application.java new file mode 100755 index 0000000..b14e00c --- /dev/null +++ b/Chapter3-1-7/src/main/java/com/didispace/Application.java @@ -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; + } + +} diff --git a/Chapter3-1-7/src/main/java/com/didispace/dto/UserDto.java b/Chapter3-1-7/src/main/java/com/didispace/dto/UserDto.java new file mode 100644 index 0000000..55b68af --- /dev/null +++ b/Chapter3-1-7/src/main/java/com/didispace/dto/UserDto.java @@ -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; + +} \ No newline at end of file diff --git a/Chapter3-1-7/src/main/resources/application.properties b/Chapter3-1-7/src/main/resources/application.properties new file mode 100755 index 0000000..e69de29