fixed table collection error

This commit is contained in:
开源海哥 2023-06-13 14:48:09 +08:00
parent 4e2e874c91
commit b89ea85dad
2 changed files with 7 additions and 25 deletions

View File

@ -97,13 +97,6 @@ public class TableInfo {
private List<UpdateListener> onUpdateListeners;
private List<SetListener> onSetListeners;
/**
* @deprecated 该功能有更好的方式实现此属性可能会被移除
*/
@Deprecated
private Map<String, Class<?>> joinTypes;
/**
* 对应 MapperXML 配置文件中 {@code <resultMap>} 标签下的 {@code <association>} 标签
*/
@ -297,21 +290,6 @@ public class TableInfo {
return propertyColumnMapping.get(property);
}
public Map<String, Class<?>> getJoinTypes() {
return joinTypes;
}
public void setJoinTypes(Map<String, Class<?>> joinTypes) {
this.joinTypes = joinTypes;
}
public void addJoinType(String fieldName, Class<?> clazz) {
if (joinTypes == null) {
joinTypes = new HashMap<>();
}
joinTypes.put(fieldName, clazz);
}
public Map<String, Class<?>> getAssociationType() {
return associationType;
}

View File

@ -48,7 +48,8 @@ import java.util.stream.Collectors;
public class TableInfoFactory {
private TableInfoFactory() {}
private TableInfoFactory() {
}
private static final Set<Class<?>> defaultSupportColumnTypes = CollectionUtil.newHashSet(
int.class, Integer.class,
@ -216,12 +217,15 @@ public class TableInfoFactory {
if (Collection.class.isAssignableFrom(fieldType)) {
ParameterizedType genericType = (ParameterizedType) field.getGenericType();
Type actualTypeArgument = genericType.getActualTypeArguments()[0];
tableInfo.addCollectionType(field, (Class<?>) actualTypeArgument);
//需排除 List<String> List<Long> 等场景
if (!defaultSupportColumnTypes.contains(actualTypeArgument)) {
tableInfo.addCollectionType(field, (Class<?>) actualTypeArgument);
}
}
// 实体类嵌套
else if (!Map.class.isAssignableFrom(fieldType)
&& !fieldType.isArray()) {
// tableInfo.addJoinType(field.getName(), fieldType);
tableInfo.addAssociationType(field.getName(), fieldType);
}
// 不支持的类型直接跳过