起因:web開發中,希望代碼中統一使用java 8的日期時間類型,特別是:java.time.ZonedDateTime
爲什麼不用java.util.Date或java.sql.Timestamp?
1. 官方說明:JSR310 的 2.5 What need of the Java community will be addressed by the proposed specification?
2. 個人只是覺得ISO 8601的格式設計很易讀、 ZonedDateTime.now()等方法一步到位非常好用。
目前用到的工具配置:
Mybatis
添加MyBatis Type Handlers for JSR 310: Date and Time API,按說明即可。
用Mybatis-Spring的話可以增加SqlSessionFactoryBean配置:<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 指向mybatis-config.xml --> <property name="configLocation" value="classpath:mybatis-config.xml"/> </bean>
Jackson
添加jackson-modules-java8