mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 17:48:25 +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());
|
boolean withCircularReference = context.contains(entityClass.getName());
|
||||||
String resultMapId = entityClass.getName() + (withCircularReference ? "$nested" : "");
|
if (withCircularReference) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String resultMapId = entityClass.getName();
|
||||||
context.add(resultMapId);
|
context.add(resultMapId);
|
||||||
|
|
||||||
if (configuration.hasResultMap(resultMapId)) {
|
if (configuration.hasResultMap(resultMapId)) {
|
||||||
@ -734,30 +738,34 @@ public class TableInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// <resultMap> 标签下的 <association> 标签映射
|
// <resultMap> 标签下的 <association> 标签映射
|
||||||
if (!withCircularReference && associationType != null) {
|
if (associationType != null) {
|
||||||
associationType.forEach((fieldName, fieldType) -> {
|
associationType.forEach((fieldName, fieldType) -> {
|
||||||
// 获取嵌套类型的信息,也就是 javaType 属性
|
// 获取嵌套类型的信息,也就是 javaType 属性
|
||||||
TableInfo tableInfo = TableInfoFactory.ofEntityClass(fieldType);
|
TableInfo tableInfo = TableInfoFactory.ofEntityClass(fieldType);
|
||||||
// 构建嵌套类型的 ResultMap 对象,也就是 <association> 标签下的内容
|
// 构建嵌套类型的 ResultMap 对象,也就是 <association> 标签下的内容
|
||||||
ResultMap nestedResultMap = tableInfo.doBuildResultMap(configuration, context);
|
ResultMap nestedResultMap = tableInfo.doBuildResultMap(configuration, context);
|
||||||
resultMappings.add(new ResultMapping.Builder(configuration, fieldName)
|
if (nestedResultMap != null) {
|
||||||
.javaType(fieldType)
|
resultMappings.add(new ResultMapping.Builder(configuration, fieldName)
|
||||||
.nestedResultMapId(nestedResultMap.getId())
|
.javaType(fieldType)
|
||||||
.build());
|
.nestedResultMapId(nestedResultMap.getId())
|
||||||
|
.build());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// <resultMap> 标签下的 <collection> 标签映射
|
// <resultMap> 标签下的 <collection> 标签映射
|
||||||
if (!withCircularReference && collectionType != null) {
|
if (collectionType != null) {
|
||||||
collectionType.forEach((field, genericClass) -> {
|
collectionType.forEach((field, genericClass) -> {
|
||||||
// 获取集合泛型类型的信息,也就是 ofType 属性
|
// 获取集合泛型类型的信息,也就是 ofType 属性
|
||||||
TableInfo tableInfo = TableInfoFactory.ofEntityClass(genericClass);
|
TableInfo tableInfo = TableInfoFactory.ofEntityClass(genericClass);
|
||||||
// 构建嵌套类型的 ResultMap 对象,也就是 <collection> 标签下的内容
|
// 构建嵌套类型的 ResultMap 对象,也就是 <collection> 标签下的内容
|
||||||
ResultMap nestedResultMap = tableInfo.doBuildResultMap(configuration, context);
|
ResultMap nestedResultMap = tableInfo.doBuildResultMap(configuration, context);
|
||||||
resultMappings.add(new ResultMapping.Builder(configuration, field.getName())
|
if (nestedResultMap != null) {
|
||||||
.javaType(field.getType())
|
resultMappings.add(new ResultMapping.Builder(configuration, field.getName())
|
||||||
.nestedResultMapId(nestedResultMap.getId())
|
.javaType(field.getType())
|
||||||
.build());
|
.nestedResultMapId(nestedResultMap.getId())
|
||||||
|
.build());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user