MyBatis-Spring-Boot icon indicating copy to clipboard operation
MyBatis-Spring-Boot copied to clipboard

使用该项目代码集成自定义的mybatis typeHandler时报错 IllegalStateException: No typehandler found for property XXX

Open youblade opened this issue 8 years ago • 10 comments

问题重现步骤:

使用原项目代码作如下修改: 1、UserInfo类中增加如下成员变量:

private LocalDateTime createTime;

2、项目引入typeHandlers(https://github.com/javaplugs/mybatis-types) 1)pom.xml中添加依赖:

        <dependency>
            <groupId>com.github.javaplugs</groupId>
            <artifactId>mybatis-types</artifactId>
            <version>0.3</version>
        </dependency>

    <repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>

2)MyBatisConfig类中sqlSessionFactoryBean()方法增加:

bean.setTypeHandlersPackage("com.github.javaplugs.mybatis");

3、打包运行

mvn clean package -DskipTests=true
java -jar target/mybatis-spring-boot-1.0.0-SNAPSHOT.jar

即报错: IllegalStateException: No typehandler found for property createTime

补充说明

若直接将依赖的mybatis-types中的代码LocalDateTimeTypeHandler拷贝到项目本地的代码路径下,比如util包,再修改MyBatisConfig中的配置:

bean.setTypeHandlersPackage("tk.mybatis.springboot.util");

重新打包运行

mvn clean package -DskipTests=true
java -jar target/mybatis-spring-boot-1.0.0-SNAPSHOT.jar

则不再出现该错误

youblade avatar May 19 '16 09:05 youblade

java -jar形式能够成功启动。请问一下如何在开发中调试,总不能每次都打成jar再开发吧。

ghost avatar Jun 26 '16 14:06 ghost

我用的IDEA,直接启动 main 方法。

abel533 avatar Jun 29 '16 13:06 abel533

好的

ghost avatar Jul 01 '16 13:07 ghost

映射文件里有collection property="roles" ofType="tk.mybatis.springboot.model.SysRole"> collection 报错 Caused by: java.lang.IllegalStateException: No typehandler found for property roles

@abel533

vinplezhang avatar Jun 13 '17 15:06 vinplezhang

映射文件里有collection property="roles" ofType="tk.mybatis.springboot.model.SysRole">

collection 报错 Caused by: java.lang.IllegalStateException: No typehandler found for property roles

@abel533 我也碰到此问题,好像用了通用Mapper就不支持集合映射了

ijaychang avatar Aug 29 '17 05:08 ijaychang

@jaychang9 非表字段加注解忽略。以后版本会自动忽略一些类型的字段。

abel533 avatar Aug 29 '17 07:08 abel533

@abel533 我也遇到这个问题了。使用@Transient忽略后,并不能把值读出来。请教下如何处理这种情况? 对象属性没有问题,集合属性就会报这个错 。谢谢!

wenkyzhang avatar Sep 02 '17 09:09 wenkyzhang

@wenkyzhang 这种要手写!

abel533 avatar Sep 04 '17 12:09 abel533

@abel533 那一般是写成List通用的好,还是每个实体类都需要写一个? 对于BaseTypeHandler<List<T>>的实现,有些方法的值还不是太明白。谢谢!

wenkyzhang avatar Sep 05 '17 02:09 wenkyzhang

@youblade 这种本地跟jar报运行的差异是怎么解决的呢?

wuxiy avatar May 21 '19 11:05 wuxiy