From 4e2e874c911554f5f733b09f399e692acc6fa55a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=80=E6=BA=90=E6=B5=B7=E5=93=A5?= Date: Tue, 13 Jun 2023 13:27:28 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=20TableInfo.buildResultMap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatisflex/core/mybatis/FlexConfiguration.java | 2 +- .../java/com/mybatisflex/core/table/TableInfo.java | 12 ++++++------ .../main/java/com/mybatisflex/test/model/Role.java | 12 ++++++++++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexConfiguration.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexConfiguration.java index af7b4994..cf015789 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexConfiguration.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexConfiguration.java @@ -194,7 +194,7 @@ public class FlexConfiguration extends Configuration { if (hasResultMap(resultMapId)) { resultMap = getResultMap(resultMapId); } else { - resultMap = tableInfo.buildResultMap(this); + resultMap = tableInfo.buildResultMap(this, true); } return new MappedStatement.Builder(ms.getConfiguration(), ms.getId(), ms.getSqlSource(), ms.getSqlCommandType()) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java index eb97d66f..5867e614 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java @@ -707,8 +707,8 @@ public class TableInfo { } - public ResultMap buildResultMap(Configuration configuration) { - String resultMapId = entityClass.getName(); + public ResultMap buildResultMap(Configuration configuration, boolean withNested) { + String resultMapId = entityClass.getName() + (withNested ? "" : "$nested"); if (configuration.hasResultMap(resultMapId)) { return configuration.getResultMap(resultMapId); } @@ -746,12 +746,12 @@ public class TableInfo { } // 标签下的 标签映射 - if (associationType != null) { + if (withNested && associationType != null) { associationType.forEach((fieldName, fieldType) -> { // 获取嵌套类型的信息,也就是 javaType 属性 TableInfo tableInfo = TableInfoFactory.ofEntityClass(fieldType); // 构建嵌套类型的 ResultMap 对象,也就是 标签下的内容 - ResultMap nestedResultMap = tableInfo.buildResultMap(configuration); + ResultMap nestedResultMap = tableInfo.buildResultMap(configuration, false); resultMappings.add(new ResultMapping.Builder(configuration, fieldName) .javaType(fieldType) .nestedResultMapId(nestedResultMap.getId()) @@ -760,12 +760,12 @@ public class TableInfo { } // 标签下的 标签映射 - if (collectionType != null) { + if (withNested && collectionType != null) { collectionType.forEach((field, genericClass) -> { // 获取集合泛型类型的信息,也就是 ofType 属性 TableInfo tableInfo = TableInfoFactory.ofEntityClass(genericClass); // 构建嵌套类型的 ResultMap 对象,也就是 标签下的内容 - ResultMap nestedResultMap = tableInfo.buildResultMap(configuration); + ResultMap nestedResultMap = tableInfo.buildResultMap(configuration, false); resultMappings.add(new ResultMapping.Builder(configuration, field.getName()) .javaType(field.getType()) .nestedResultMapId(nestedResultMap.getId()) diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/Role.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/Role.java index d6a1e97e..7ef62832 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/Role.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/Role.java @@ -19,6 +19,8 @@ package com.mybatisflex.test.model; import com.mybatisflex.annotation.Id; import com.mybatisflex.annotation.Table; +import java.util.List; + /** * 角色。 * @@ -33,6 +35,8 @@ public class Role implements Comparable { private String roleKey; private String roleName; + private List userVOS; + public Integer getRoleId() { return roleId; } @@ -57,6 +61,14 @@ public class Role implements Comparable { this.roleName = roleName; } + public List getUserVOS() { + return userVOS; + } + + public void setUserVOS(List userVOS) { + this.userVOS = userVOS; + } + @Override public String toString() { return "Role{" +