Mapper
Mapper copied to clipboard
EntityTable 中对于 typeHandler 的处理
EntityTable 中对于 typeHandler 的处理应该先从 TypeHandlerRegister 中获取,获取不到再实例化。因为有些 TypeHandler 使用通过Spring 管理的,直接实例化无法注入依赖。
public ResultMap getResultMap(Configuration configuration) {
if (this.resultMap != null) {
return this.resultMap;
}
if (entityClassColumns == null || entityClassColumns.size() == 0) {
return null;
}
List<ResultMapping> resultMappings = new ArrayList<ResultMapping>();
for (EntityColumn entityColumn : entityClassColumns) {
String column = entityColumn.getColumn();
//去掉可能存在的分隔符
Matcher matcher = DELIMITER.matcher(column);
if(matcher.find()){
column = matcher.group(1);
}
ResultMapping.Builder builder = new ResultMapping.Builder(configuration, entityColumn.getProperty(), column, entityColumn.getJavaType());
if (entityColumn.getJdbcType() != null) {
builder.jdbcType(entityColumn.getJdbcType());
}
if (entityColumn.getTypeHandler() != null) {
try {
builder.typeHandler(getInstance(entityColumn.getJavaType(),entityColumn.getTypeHandler()));
} catch (Exception e) {
throw new MapperException(e);
}
}
List<ResultFlag> flags = new ArrayList<ResultFlag>();
if (entityColumn.isId()) {
flags.add(ResultFlag.ID);
}
builder.flags(flags);
resultMappings.add(builder.build());
}
ResultMap.Builder builder = new ResultMap.Builder(configuration, "BaseMapperResultMap", this.entityClass, resultMappings, true);
this.resultMap = builder.build();
return this.resultMap;
}
这个是否有好的解决办法