From b4cc750394fbf6a4db2c01d601116861fd142095 Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Fri, 23 Dec 2022 13:08:25 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=AF=B9=E4=B8=80=E5=B5=8C=E5=A5=97bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MybatisPlusJoinAutoConfiguration.java | 1 + .../autoconfigure/MybatisPlusJoinProperties.java | 5 +++++ .../additional-spring-configuration-metadata.json | 8 +++++++- .../github/yulichang/config/ConfigProperties.java | 2 +- .../github/yulichang/config/InterceptorConfig.java | 2 +- .../github/yulichang/interceptor/MPJInterceptor.java | 4 +++- .../yulichang/wrapper/interfaces/QueryLabel.java | 2 +- .../yulichang/wrapper/resultmap/MybatisLabel.java | 12 ++++++------ 8 files changed, 25 insertions(+), 11 deletions(-) diff --git a/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinAutoConfiguration.java b/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinAutoConfiguration.java index b2c79a3..b8adb5e 100644 --- a/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinAutoConfiguration.java +++ b/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinAutoConfiguration.java @@ -59,6 +59,7 @@ public class MybatisPlusJoinAutoConfiguration { ConfigProperties.subTableLogic = properties.getSubTableLogic(); ConfigProperties.msCache = properties.isMsCache(); ConfigProperties.tableAlias = properties.getTableAlias(); + ConfigProperties.tableAlias = properties.getJoinPrefix(); } /** diff --git a/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java b/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java index f3d842b..3b8f56d 100644 --- a/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java +++ b/mybatis-plus-join-boot-starter/src/main/java/com/github/yulichang/autoconfigure/MybatisPlusJoinProperties.java @@ -34,4 +34,9 @@ public class MybatisPlusJoinProperties { * MappedStatement缓存 */ private boolean msCache = true; + + /** + * 连表查询重复字段名前缀 + */ + private String joinPrefix = "t"; } diff --git a/mybatis-plus-join-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/mybatis-plus-join-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 04c9c5b..33b9bab 100644 --- a/mybatis-plus-join-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/mybatis-plus-join-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -30,6 +30,12 @@ "defaultValue": "t", "type": "java.lang.String", "description": "表别名." + }, + { + "name": "mybatis-plus-join.join-prefix", + "defaultValue": "t", + "type": "java.lang.String", + "description": "重复字段前缀." } ] -} \ No newline at end of file +} diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/ConfigProperties.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/ConfigProperties.java index eda7d8c..c15b174 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/ConfigProperties.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/ConfigProperties.java @@ -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"; } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/InterceptorConfig.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/InterceptorConfig.java index a893038..f4441ac 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/InterceptorConfig.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/InterceptorConfig.java @@ -29,7 +29,7 @@ public class InterceptorConfig { //打印banner System.out.println(" _ _ |_ _ _|_. ___ _ | _ . _ . _ \n" + "| | |\\/|_)(_| | |_\\ |_)||_|_\\ | (_) | | | \n" + - " / | / 1.3.11"); + " / | / 1.4.0"); } } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java index c2c57d5..7d7d3a2 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/interceptor/MPJInterceptor.java @@ -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 childMapping = new ArrayList<>(resultList.size()); for (Result r : resultList) { @@ -298,7 +300,7 @@ public class MPJInterceptor implements Interceptor { * @return 唯一列名 */ private String getColumn(Set pool, String columnName) { - columnName = "join_" + columnName; + columnName = ConfigProperties.joinPrefix + columnName; if (!pool.contains(columnName)) { pool.add(columnName); return columnName; diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/QueryLabel.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/QueryLabel.java index b9b5651..c4e9058 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/QueryLabel.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/QueryLabel.java @@ -153,7 +153,7 @@ public interface QueryLabel { Field field = MPJReflectionKit.getFieldMap(dtoClass).get(dtoFieldName); Assert.isFalse(Collection.class.isAssignableFrom(field.getType()), "association 不支持集合类"); MybatisLabel.Builder builder = new MybatisLabel.Builder<>(Objects.isNull(index) ? null : index.toString(), - dtoFieldName, child, field.getType(), (Class) child, false); + dtoFieldName, child, field.getType(), (Class) field.getType(), false); MybatisLabel.Builder cfBuilder = collection.apply(builder); addLabel(cfBuilder.build()); return getChildren(); diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/MybatisLabel.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/MybatisLabel.java index a4f1c83..cda4d1b 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/MybatisLabel.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/resultmap/MybatisLabel.java @@ -181,22 +181,22 @@ public class MybatisLabel { return this; } - public Builder selectAssociation(Class child, SFunction dtoField, - MFunc> collection) { - return selectAssociation(null, child, dtoField, collection); + public Builder association(Class child, SFunction dtoField, + MFunc> collection) { + return association(null, child, dtoField, collection); } /** * 嵌套 */ - public Builder selectAssociation(Integer index, Class child, SFunction dtoField, - MFunc> collection) { + public Builder association(Integer index, Class child, SFunction dtoField, + MFunc> collection) { String dtoFieldName = LambdaUtils.getName(dtoField); Class dtoClass = LambdaUtils.getEntityClass(dtoField); Field field = MPJReflectionKit.getFieldMap(dtoClass).get(dtoFieldName); Assert.isFalse(Collection.class.isAssignableFrom(field.getType()), "association 不支持集合类"); MybatisLabel.Builder builder = new MybatisLabel.Builder<>(Objects.isNull(index) ? null : index.toString(), - dtoFieldName, child, field.getType(), (Class) child, false); + dtoFieldName, child, field.getType(), (Class) field.getType(), false); mybatisLabel.mybatisLabels.add(collection.apply(builder).build()); return this; }