Mybatis-Plus SQLFeatureNotSupportedException: getObject with type问题解决
问题描述:
Error attempting to get column 'modify_time' from result set. Cause: java.sql.SQLFeatureNotSupportedException: getObject with type
; getObject with type; nested exception is java.sql.SQLFeatureNotSupportedException: getObject with type, stackTraceorg.springframework.dao.InvalidDataAccessApiUsageException: Error attempting to get column 'modify_time' from result set. Cause: java.sql.SQLFeatureNotSupportedException: getObject with type
问题分析:
1、mybatis-plus和shardingsphere集成,数据库datetime类型转java的LocalDateTime类型时调用org.apache.ibatis.type.LocalDateTimeTypeHandler.getNullableResult方法,会导致找不到LocalDateTime类型的ResultSet.getObject()方法。
解决办法:
(1)增加mybatis-typehandlers-jsr310依赖,该依赖重写了LocalDateTimeTypeHandler类,不过要加在mybatis-plus-boot-starter依赖之前。
<dependency><groupId>org.mybatis</groupId><artifactId>mybatis-typehandlers-jsr310</artifactId><version>1.0.1</version></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId></dependency>
(2)自己重写LocalDateTimeTypeHandler类,具体步骤请参考以下博客。
Mybatis 自定义LocalDateTime类型处理器handler_旭东怪的博客-CSDN博客人生低谷不可怕,可怕的是坚持不到人生转折点的那一天。重写LocalDateTimeTypeHandler ,解决shardingsphere + mybatis LocalDateTime转换问题。旭东怪的个人空间-旭东怪个人主页-哔哩哔哩视频。https://blog.csdn.net/qq_38974638/article/details/129762669?spm=1001.2014.3001.5501
旭东怪的个人空间-旭东怪个人主页-哔哩哔哩视频哔哩哔哩旭东怪的个人空间,提供旭东怪分享的视频、音频、文章、动态、收藏等内容,关注旭东怪账号,第一时间了解UP注动态。人生低谷不可怕,可怕的是坚持不到人生转折点的那一天https://space.bilibili.com/484264966?spm_id_from=333.337.search-card.all.click