Error attempting to get column 'create_time' from result set. Cause: java.sql.SQLFeatureNotSupported

一、问题

出现报错:Error attempting to get column ‘create_time’ from result set. Cause: java.sql.SQLFeatureNotSupported
Error attempting to get column 'create_time' from result set. Cause: java.sql.SQLFeatureNotSupported_第1张图片

出现错误的原因:因为我的表的createtime类型为DateTime,通过mybatis-plus代码生成器生成的是LocalDateTime,而Java8里面新出来了一些API,LocalDate、LocalTime、LocalDateTime ,但是在默认的情况下,在mybatis里面不支持java8的时间、日期

二、有两种方法可以解决

第一种方法:将mybatis降到3.5.0版本

Error attempting to get column 'create_time' from result set. Cause: java.sql.SQLFeatureNotSupported_第2张图片

第二种方法:更改javabean类中的类型

Error attempting to get column 'create_time' from result set. Cause: java.sql.SQLFeatureNotSupported_第3张图片

因为我是用mybatis-plus生成的,所以我在mybatis-plus代码生成器中进行配置

配置时间类型对应策略

Error attempting to get column 'create_time' from result set. Cause: java.sql.SQLFeatureNotSupported_第4张图片
在DateType源码中有三种策略可供选择

public enum DateType {
    /**
     * 只使用 java.util.date 代替
     */
    ONLY_DATE,
    /**
     * 使用 java.sql 包下的
     */
    SQL_PACK,
    /**
     * 使用 java.time 包下的
     * 

java8 新的时间类型

*/
TIME_PACK }

最后运行:
在这里插入图片描述

你可能感兴趣的:(mybatis)