mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
fix 对一嵌套bug
This commit is contained in:
parent
c6c1481899
commit
b4cc750394
@ -59,6 +59,7 @@ public class MybatisPlusJoinAutoConfiguration {
|
||||
ConfigProperties.subTableLogic = properties.getSubTableLogic();
|
||||
ConfigProperties.msCache = properties.isMsCache();
|
||||
ConfigProperties.tableAlias = properties.getTableAlias();
|
||||
ConfigProperties.tableAlias = properties.getJoinPrefix();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,4 +34,9 @@ public class MybatisPlusJoinProperties {
|
||||
* MappedStatement缓存
|
||||
*/
|
||||
private boolean msCache = true;
|
||||
|
||||
/**
|
||||
* 连表查询重复字段名前缀
|
||||
*/
|
||||
private String joinPrefix = "t";
|
||||
}
|
||||
|
@ -30,6 +30,12 @@
|
||||
"defaultValue": "t",
|
||||
"type": "java.lang.String",
|
||||
"description": "表别名."
|
||||
},
|
||||
{
|
||||
"name": "mybatis-plus-join.join-prefix",
|
||||
"defaultValue": "t",
|
||||
"type": "java.lang.String",
|
||||
"description": "重复字段前缀."
|
||||
}
|
||||
]
|
||||
}
|
@ -7,6 +7,6 @@ package com.github.yulichang.config;
|
||||
public class ConfigProperties {
|
||||
public static boolean subTableLogic = true;
|
||||
public static boolean msCache = true;
|
||||
|
||||
public static String tableAlias = "t";
|
||||
public static String joinPrefix = "t";
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class InterceptorConfig {
|
||||
//打印banner
|
||||
System.out.println(" _ _ |_ _ _|_. ___ _ | _ . _ . _ \n" +
|
||||
"| | |\\/|_)(_| | |_\\ |_)||_|_\\ | (_) | | | \n" +
|
||||
" / | / 1.3.11");
|
||||
" / | / 1.4.0");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,6 +223,8 @@ public class MPJInterceptor implements Interceptor {
|
||||
.append(mybatisLabel.getEntityClass().getName())
|
||||
.append(StringPool.UNDERSCORE)
|
||||
.append(mybatisLabel.getOfType().getName())
|
||||
.append(StringPool.UNDERSCORE)
|
||||
.append(mybatisLabel.getProperty())
|
||||
.append(StringPool.UNDERSCORE);
|
||||
List<ResultMapping> childMapping = new ArrayList<>(resultList.size());
|
||||
for (Result r : resultList) {
|
||||
@ -298,7 +300,7 @@ public class MPJInterceptor implements Interceptor {
|
||||
* @return 唯一列名
|
||||
*/
|
||||
private String getColumn(Set<String> pool, String columnName) {
|
||||
columnName = "join_" + columnName;
|
||||
columnName = ConfigProperties.joinPrefix + columnName;
|
||||
if (!pool.contains(columnName)) {
|
||||
pool.add(columnName);
|
||||
return columnName;
|
||||
|
@ -153,7 +153,7 @@ public interface QueryLabel<Children> {
|
||||
Field field = MPJReflectionKit.getFieldMap(dtoClass).get(dtoFieldName);
|
||||
Assert.isFalse(Collection.class.isAssignableFrom(field.getType()), "association 不支持集合类");
|
||||
MybatisLabel.Builder<C, F> builder = new MybatisLabel.Builder<>(Objects.isNull(index) ? null : index.toString(),
|
||||
dtoFieldName, child, field.getType(), (Class<F>) child, false);
|
||||
dtoFieldName, child, field.getType(), (Class<F>) field.getType(), false);
|
||||
MybatisLabel.Builder<C, F> cfBuilder = collection.apply(builder);
|
||||
addLabel(cfBuilder.build());
|
||||
return getChildren();
|
||||
|
@ -181,22 +181,22 @@ public class MybatisLabel<E, T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <A, B> Builder<E, T> selectAssociation(Class<A> child, SFunction<T, B> dtoField,
|
||||
MFunc<MybatisLabel.Builder<A, B>> collection) {
|
||||
return selectAssociation(null, child, dtoField, collection);
|
||||
public <A, B> Builder<E, T> association(Class<A> child, SFunction<T, B> dtoField,
|
||||
MFunc<MybatisLabel.Builder<A, B>> collection) {
|
||||
return association(null, child, dtoField, collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* 嵌套
|
||||
*/
|
||||
public <A, B> Builder<E, T> selectAssociation(Integer index, Class<A> child, SFunction<T, B> dtoField,
|
||||
MFunc<MybatisLabel.Builder<A, B>> collection) {
|
||||
public <A, B> Builder<E, T> association(Integer index, Class<A> child, SFunction<T, B> dtoField,
|
||||
MFunc<MybatisLabel.Builder<A, B>> collection) {
|
||||
String dtoFieldName = LambdaUtils.getName(dtoField);
|
||||
Class<T> dtoClass = LambdaUtils.getEntityClass(dtoField);
|
||||
Field field = MPJReflectionKit.getFieldMap(dtoClass).get(dtoFieldName);
|
||||
Assert.isFalse(Collection.class.isAssignableFrom(field.getType()), "association 不支持集合类");
|
||||
MybatisLabel.Builder<A, B> builder = new MybatisLabel.Builder<>(Objects.isNull(index) ? null : index.toString(),
|
||||
dtoFieldName, child, field.getType(), (Class<B>) child, false);
|
||||
dtoFieldName, child, field.getType(), (Class<B>) field.getType(), false);
|
||||
mybatisLabel.mybatisLabels.add(collection.apply(builder).build());
|
||||
return this;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user