# spring-boot-jpa-joda-time
**Repository Path**: kevinlieu/spring-boot-jpa-joda-time
## Basic Information
- **Project Name**: spring-boot-jpa-joda-time
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2017-07-21
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
#SPRING BOOT:Hibernate实现的JPA中使用joda-time
`joda-time`在java8出现之前很长时间作为Java中处理日期时间的事实标准,但是想要在JPA实体类中使用joda-time需要做以下配置
##dependencies
在`pom.xml`文件中添加
```
joda-time
joda-time
org.jadira.usertype
usertype.extended
5.0.0.GA
```
##application.properties
在`src/main/resources/application.properties`配置文件中添加
```
spring.jpa.properties.jadira.usertype.autoRegisterUserTypes = true
```
##JPA实体类
```
// 映射为 DATETIME 类型字段 (MySQL)
private DateTime createTime;
// 映射为 DATE 类型字段 (MySQL)
private LocalDate birthdayDate;
```
##绑定json数据
在`pom.xml`中添加
```
com.fasterxml.jackson.datatype
jackson-datatype-joda
```
在controller中接收json请求
```
@RequestMapping("/add")
@ResponseBody
public User addUser(@RequestBody User user) {
// ....
}
```
发送一个Content-Type为application/json的请求, addUser方法将接收一个User实例
```
{"createTime":"1970-01-01T00:00:00","birthdayDate":"1970-01-01"}
```