JSR310-新日期API的使用总结

一、数据库字段类型和Java类型的对应关系

MySQL字段类型 旧日期时间API JSR310日期时间API
year java.sql.Date LocalDate
date java.sql.Date LocalDate
time java.sql.Time LocalTime
timestamp java.sql.Timestamp LocalDateTime
datetime java.sql.Timestamp LocalTime

 

 

 

 

 

 

补充说明:https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-type-conversions.html

二、兼容提示

1、从 3.4.5 开始,MyBatis 默认支持 JSR-310(日期和时间 API) ,https://mybatis.org/mybatis-3/zh/configuration.html#typeHandlers

2、The JPA 2.2 version has officially introduced the support for Java 8 Date and Time API,https://www.baeldung.com/jpa-java-time

3、对数据库连接池druid的版本也有一定的要求,https://github.com/mybatis/mybatis-3/issues/1516

三、目前的版本

类库 版本
SpringBoot 2.2.6.RELEASE
mybatis-spring-boot-starter 2.1.2
druid-spring-boot-starter 1.1.22
   

 

 

 

 

四、趟坑过程

java.util.Date --> java.sql.Date --> 注解 + java.util.Date --> JSR310日期时间API

五、其他补充

1、JSR310-新日期API(完结篇)-生产实战

2、Introduction to the Java 8 Date/Time API

3、Migrating to the New Java 8 Date Time API

4、Convert Date to LocalDate or LocalDateTime and Back

 

posted @ 2020-09-15 17:28  又是火星人  阅读(477)  评论(0编辑  收藏  举报