一. 前言
小熙最近项目使用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 以下,但是有些特性还是用到了,不降当然更好。