mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
重构 TableInfo.buildResultMap
This commit is contained in:
parent
4cc7fdb4e7
commit
4e2e874c91
@ -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())
|
||||
|
||||
@ -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 {
|
||||
}
|
||||
|
||||
// <resultMap> 标签下的 <association> 标签映射
|
||||
if (associationType != null) {
|
||||
if (withNested && associationType != null) {
|
||||
associationType.forEach((fieldName, fieldType) -> {
|
||||
// 获取嵌套类型的信息,也就是 javaType 属性
|
||||
TableInfo tableInfo = TableInfoFactory.ofEntityClass(fieldType);
|
||||
// 构建嵌套类型的 ResultMap 对象,也就是 <association> 标签下的内容
|
||||
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 {
|
||||
}
|
||||
|
||||
// <resultMap> 标签下的 <collection> 标签映射
|
||||
if (collectionType != null) {
|
||||
if (withNested && collectionType != null) {
|
||||
collectionType.forEach((field, genericClass) -> {
|
||||
// 获取集合泛型类型的信息,也就是 ofType 属性
|
||||
TableInfo tableInfo = TableInfoFactory.ofEntityClass(genericClass);
|
||||
// 构建嵌套类型的 ResultMap 对象,也就是 <collection> 标签下的内容
|
||||
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())
|
||||
|
||||
@ -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<Role> {
|
||||
private String roleKey;
|
||||
private String roleName;
|
||||
|
||||
private List<UserVO> userVOS;
|
||||
|
||||
public Integer getRoleId() {
|
||||
return roleId;
|
||||
}
|
||||
@ -57,6 +61,14 @@ public class Role implements Comparable<Role> {
|
||||
this.roleName = roleName;
|
||||
}
|
||||
|
||||
public List<UserVO> getUserVOS() {
|
||||
return userVOS;
|
||||
}
|
||||
|
||||
public void setUserVOS(List<UserVO> userVOS) {
|
||||
this.userVOS = userVOS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Role{" +
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user