here과 같이 Spring Integration과 함께 MyBatis를 사용하고 있습니다.MyBatis/Spring에서 사용자 정의 유형 사용하기
Java Date API 대신 Joda Date API를 사용하고 있습니다. 이제는 MyBatis가 Joda Date API를 인식하고이를 쿼리 할 수 있습니다.
지금 이것을 달성하기 위해 문서화 된 방법은 우리가 올바른 주석을 사용하는 경우, MyBatis로 사용자 정의 핸들러를 선택하고 SqlSessionFactory는에 등록됩니다 가정 오전 DateTypeHandler
을 사용하는 것입니다.
그래서 내 수업 보이는이 내 사용자 정의 타입 핸들러를 등록하지 않는 방법
@MappedTypes(value = DateTime.class)
@MappedJdbcTypes(value = {JdbcType.DATE,JdbcType.TIME,JdbcType.TIMESTAMP})
public class MyBatisJodaDateTimeType extends DateTypeHandler {
......
.....
}
일부처럼 ..., 내가 필요하고 무엇을, 응용 프로그램 시작시이 같은 코드를 작성 ...
입니다SqlSessionFactory mybatisSessionFactory = applicationContext.getBean("sqlSessionFactory", SqlSessionFactory.class);
MyBatisJodaDateTimeType myBatisJodaDateTimeType = applicationContext.getBean("myBatisJodaDateTimeType", MyBatisJodaDateTimeType.class);
mybatisSessionFactory.getConfiguration().getTypeHandlerRegistry().register(DateTime.class, myBatisJodaDateTimeType);
mybatisSessionFactory.getConfiguration().getTypeHandlerRegistry().register(DateTime.class, JdbcType.DATE, myBatisJodaDateTimeType);
mybatisSessionFactory.getConfiguration().getTypeHandlerRegistry().register(DateTime.class, JdbcType.TIME, myBatisJodaDateTimeType);
mybatisSessionFactory.getConfiguration().getTypeHandlerRegistry().register(DateTime.class, JdbcType.TIMESTAMP, myBatisJodaDateTimeType);
mybatisSessionFactory.getConfiguration().getTypeHandlerRegistry().register(DateTime.class, null, myBatisJodaDateTimeType);
나는 쓰레기처럼 보입니다. 나는 그것을 피하고 싶습니다. MyBatis가 내 애플리케이션을 검색하여 내 사용자 정의 유형 핸들러를 자동으로 등록 할 수 없습니까?
나는 내가이의 MyBatis 코드를 검사했고, 거기에 내 처리기를 찾을 수 있기 때문에 (단지 주석을 사용) 내 타입이 등록되지 않았 음을 확신합니다 ....
당신은 우리가 Typehandler에 배치 주석을 제거하고 또한 핸들러의 수동 등록을 수행하는 코드를 제거 할 수 있음을 시사하고 있습니까? 어쩌면 작동 할 수 있을까요? ... 방금 시나리오를 테스트했는데 성공하지 못했습니다. – Sudarshan
예, 최신 MyBatis 릴리스에서 선택 및 업데이트를 위해 직접 작업 한 것입니다. 따라서 유일한 주석은 @MappedTypes (DateTime.class)입니다. – usethe4ce
어떤 버전을 알려주시겠습니까? MyBatis와 스프링 통합을 사용한다면? – Sudarshan