fix 对一嵌套bug

This commit is contained in:
yulichang 2022-12-23 16:20:17 +08:00
parent b4cc750394
commit 6be38fea0d
3 changed files with 19 additions and 9 deletions

View File

@ -59,7 +59,7 @@ public class MybatisPlusJoinAutoConfiguration {
ConfigProperties.subTableLogic = properties.getSubTableLogic(); ConfigProperties.subTableLogic = properties.getSubTableLogic();
ConfigProperties.msCache = properties.isMsCache(); ConfigProperties.msCache = properties.isMsCache();
ConfigProperties.tableAlias = properties.getTableAlias(); ConfigProperties.tableAlias = properties.getTableAlias();
ConfigProperties.tableAlias = properties.getJoinPrefix(); ConfigProperties.joinPrefix = properties.getJoinPrefix();
} }
/** /**

View File

@ -38,5 +38,5 @@ public class MybatisPlusJoinProperties {
/** /**
* 连表查询重复字段名前缀 * 连表查询重复字段名前缀
*/ */
private String joinPrefix = "t"; private String joinPrefix = "join";
} }

View File

@ -235,7 +235,7 @@ public class MPJInterceptor implements Interceptor {
SelectLabel label; SelectLabel label;
Field field = ofTypeField.get(r.getProperty()); Field field = ofTypeField.get(r.getProperty());
if (columnSet.contains(columnName)) { if (columnSet.contains(columnName)) {
columnName = getColumn(columnSet, columnName); columnName = getColumn(columnSet, columnName, 0);
label = new SelectLabel(r.getSelectNormal(), mybatisLabel.getIndex(), mybatisLabel.getOfType(), field, columnName); label = new SelectLabel(r.getSelectNormal(), mybatisLabel.getIndex(), mybatisLabel.getOfType(), field, columnName);
} else { } else {
label = new SelectLabel(r.getSelectNormal(), mybatisLabel.getIndex(), mybatisLabel.getOfType(), field); label = new SelectLabel(r.getSelectNormal(), mybatisLabel.getIndex(), mybatisLabel.getOfType(), field);
@ -299,13 +299,23 @@ public class MPJInterceptor implements Interceptor {
* @param columnName 列明 * @param columnName 列明
* @return 唯一列名 * @return 唯一列名
*/ */
private String getColumn(Set<String> pool, String columnName) { private String getColumn(Set<String> pool, String columnName, int num) {
columnName = ConfigProperties.joinPrefix + columnName; String newName = ConfigProperties.joinPrefix + getPrefix(num) + StringPool.UNDERSCORE + columnName;
if (!pool.contains(columnName)) { if (!pool.contains(newName)) {
pool.add(columnName); pool.add(newName);
return columnName; return newName;
} }
return getColumn(pool, columnName); return getColumn(pool, columnName, ++num);
}
private String getPrefix(int num) {
String s = Integer.toString(num, 25);
char[] array = s.toCharArray();
char[] chars = new char[s.length()];
for (int i = 0; i < array.length; i++) {
chars[i] = (char) (array[i] < 58 ? (array[i] + 49) : (array[i] + 10));
}
return new String(chars);
} }
/** /**