一. 前言
小熙最近項目使用MybatisPlus,是真的爽,但是畢竟是封裝的框架,一些異常是難免的。
二. 錯誤回顯
在整合druid的時候,查詢數據庫時間字段,返回LocalDateTime報以下錯誤:
org.springframework.dao.InvalidDataAccessApiUsageException: Error attempting to get column 'fetch_time' from result set. Cause: java.sql.SQLFeatureNotSupportedException
; null; nested exception is java.sql.SQLFeatureNotSupportedException
三. 原因
-
我的druid是 1.1.17 的,MybatisPlus是 3.1.1 的
-
因爲druid跟mybatis3.5.1兼容性問題,然後 mybatis-plus-generator 3.1.2引用了mybatis3.5.1 版本,因爲druid-boot-1.1.17還沒有兼容到
四. 解決
添加外部解析轉換依賴
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-typehandlers-jsr310</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.9.2</version>
</dependency>
小熙也嘗試過把MybatiPlus降到 3.5.0 以下,但是有些特性還是用到了,不降當然更好。