mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
optimize TableInfo.doBuildResultMap and close #I7D9JX
This commit is contained in:
parent
04da02260e
commit
25136b0192
@ -694,7 +694,11 @@ public class TableInfo {
|
||||
|
||||
//是否有循环引用
|
||||
boolean withCircularReference = context.contains(entityClass.getName());
|
||||
String resultMapId = entityClass.getName() + (withCircularReference ? "$nested" : "");
|
||||
if (withCircularReference) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String resultMapId = entityClass.getName();
|
||||
context.add(resultMapId);
|
||||
|
||||
if (configuration.hasResultMap(resultMapId)) {
|
||||
@ -734,30 +738,34 @@ public class TableInfo {
|
||||
}
|
||||
|
||||
// <resultMap> 标签下的 <association> 标签映射
|
||||
if (!withCircularReference && associationType != null) {
|
||||
if (associationType != null) {
|
||||
associationType.forEach((fieldName, fieldType) -> {
|
||||
// 获取嵌套类型的信息,也就是 javaType 属性
|
||||
TableInfo tableInfo = TableInfoFactory.ofEntityClass(fieldType);
|
||||
// 构建嵌套类型的 ResultMap 对象,也就是 <association> 标签下的内容
|
||||
ResultMap nestedResultMap = tableInfo.doBuildResultMap(configuration, context);
|
||||
resultMappings.add(new ResultMapping.Builder(configuration, fieldName)
|
||||
.javaType(fieldType)
|
||||
.nestedResultMapId(nestedResultMap.getId())
|
||||
.build());
|
||||
if (nestedResultMap != null) {
|
||||
resultMappings.add(new ResultMapping.Builder(configuration, fieldName)
|
||||
.javaType(fieldType)
|
||||
.nestedResultMapId(nestedResultMap.getId())
|
||||
.build());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// <resultMap> 标签下的 <collection> 标签映射
|
||||
if (!withCircularReference && collectionType != null) {
|
||||
if (collectionType != null) {
|
||||
collectionType.forEach((field, genericClass) -> {
|
||||
// 获取集合泛型类型的信息,也就是 ofType 属性
|
||||
TableInfo tableInfo = TableInfoFactory.ofEntityClass(genericClass);
|
||||
// 构建嵌套类型的 ResultMap 对象,也就是 <collection> 标签下的内容
|
||||
ResultMap nestedResultMap = tableInfo.doBuildResultMap(configuration, context);
|
||||
resultMappings.add(new ResultMapping.Builder(configuration, field.getName())
|
||||
.javaType(field.getType())
|
||||
.nestedResultMapId(nestedResultMap.getId())
|
||||
.build());
|
||||
if (nestedResultMap != null) {
|
||||
resultMappings.add(new ResultMapping.Builder(configuration, field.getName())
|
||||
.javaType(field.getType())
|
||||
.nestedResultMapId(nestedResultMap.getId())
|
||||
.build());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user