【发布时间】:2019-04-11 19:42:54
【问题描述】:
我需要有关 Spring Boot 和 MyBatis 集成的帮助。我对自定义 BaseTypeHandler 有疑问。我创建了一个映射器:
@MappedTypes({LocalDateTime.class})
public class LocalDateTimeHandler extends BaseTypeHandler<LocalDateTime> {
我添加了一个类型处理程序:
sqlSessionFactory.setTypeHandlers(new LocalDateTimeHandler[]{new LocalDateTimeHandler()});
我还有下一个错误:
org.apache.ibatis.executor.ExecutorException: No constructor found in com.some.space.SomeObject matching [java.lang.Integer, java.sql.Timestamp, java.sql.Timestamp]
SomeObject 的样子:
public class SomeObject {
private Long id;
private LocalDateTime created;
private LocalDateTime updated;
public SomeObject(Integer id, LocalDateTime created, LocalDateTime updated){
//..........
}
}
我使用的是 mybatis-spring 和 spring-boot-starter-web 版本 1.3.2。
关于使用 TypeHandlers 的所有示例都在 XML 配置上,但我需要使用 Java 配置方式。我做错了什么?
更新:
我的映射器:
@Component
@Mapper
public interface SomeObjectRepository {
@Select("SELECT * FROM some_objects")
@Results(value = {
@Result(property = "created", column = "created_date", typeHandler = LocalDateTimeTypeHandler.class, jdbcType = JdbcType.TIMESTAMP),
@Result(property = "updated", column = "updated_date", typeHandler = LocalDateTimeTypeHandler.class, jdbcType = JdbcType.TIMESTAMP)
})
List<SomeObject> getAll();
}
【问题讨论】:
-
请出示您正在使用的映射。
-
谢谢。我已经更新了一条主要信息。