Mapper icon indicating copy to clipboard operation
Mapper copied to clipboard

EntityTable 中对于 typeHandler 的处理

Open alansun2 opened this issue 4 years ago • 2 comments

EntityTable 中对于 typeHandler 的处理应该先从 TypeHandlerRegister 中获取,获取不到再实例化。因为有些 TypeHandler 使用通过Spring 管理的,直接实例化无法注入依赖。

alansun2 avatar Jan 07 '21 02:01 alansun2

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;
}

alansun2 avatar Jan 07 '21 02:01 alansun2

这个是否有好的解决办法

JK1452470209 avatar Jul 11 '23 03:07 JK1452470209