带有@MappedJdbcTypes的TypeHandler

时间:2016-02-25 22:19:14

标签: java mybatis

我想配置一个类型处理程序来将Date列转换为LocalDate(Java 8),但是我在注册时遇到了问题。我在MyBatis文档和project上建立了我的typeHandler。

映射器:

<resultMap id="clientResult" type="client">
    <id property="id" column="id" />
    <result property="name" column="name" />
    <result property="birthday" column="birthday"  />
</resultMap>

客户端类:

public class Client {
    private Long id;
    private String name;
    private java.time.LocalDate birthday;
}

类型处理程序:

@MappedJdbcTypes(value = JdbcType.DATE)
public class LocalDateHandler extends BaseTypeHandler<java.time.LocalDate> {
    ...
}

我在启动时收到此错误:

org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalStateException: No typehandler found for property birthday

经过一些调试和实验,我找到了多种解决方案。

解决方案#1

删除@MappedJdbcTypes

解决方案#2

更改@MappedJdbcTypes注释以使用未记录的includeNullJdbcType = true

@MappedJdbcTypes(value = JdbcType.DATE, includeNullJdbcType = true)

解决方案#3

jdbcType添加到resultMap媒体资源:

<result property="birthday" column="birthday" jdbcType="DATE" />

但是,我希望一切按上述方式工作。这是怎么回事?我该怎么办?

注意:我使用MyBatis 3.3.1

更新

现在这被视为一个错误:https://github.com/mybatis/mybatis-3/issues/591

0 个答案:

没有答案
相关问题