diff --git a/pom.xml b/pom.xml
index 0d58016..74851ba 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
com.github.yulichang
mybatis-plus-join
- 1.2.5
+ Gy.13.V.2.0.9
mybatis-plus-join
An enhanced toolkit of Mybatis-Plus to simplify development.
https://github.com/yulichang/mybatis-plus-join
diff --git a/src/main/java/com/baomidou/mybatisplus/core/metadata/MPJResultHelper.java b/src/main/java/com/baomidou/mybatisplus/core/metadata/MPJResultHelper.java
index d02be92..fb1aaa7 100644
--- a/src/main/java/com/baomidou/mybatisplus/core/metadata/MPJResultHelper.java
+++ b/src/main/java/com/baomidou/mybatisplus/core/metadata/MPJResultHelper.java
@@ -1,6 +1,7 @@
package com.baomidou.mybatisplus.core.metadata;
import com.baomidou.mybatisplus.core.toolkit.Assert;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
@@ -28,7 +29,7 @@ public class MPJResultHelper {
/**
* 储存反射VO信息
*/
- private static final Map, Set> VO_INFO_CACHE = new ConcurrentHashMap<>();
+ private static final Map, Map>> VO_INFO_CACHE = new ConcurrentHashMap<>();
/**
@@ -39,26 +40,30 @@ public class MPJResultHelper {
* @return: java.util.Set
* @Date: 2022/8/5 09:59
*/
- public static Set getVoTableInfo(Class> sourceEntityClass, Class> resultEntityClass) {
+ public static Map> getVoTableInfo(Class> resultEntityClass, Class>... sourceEntityClass) {
if (resultEntityClass == null || ReflectionKit.isPrimitiveOrWrapper(resultEntityClass) || resultEntityClass == String.class || resultEntityClass.isInterface()) {
return null;
}
- Set strings = VO_INFO_CACHE.get(resultEntityClass);
- if (strings == null) {
- Set set = new HashSet<>();
- MPJTableInfo info = MPJTableInfoHelper.getTableInfo(sourceEntityClass);
- Assert.notNull(info, "table can not be find");
+ Map> maps = VO_INFO_CACHE.get(resultEntityClass);
+ if (maps == null) {
+ maps = CollectionUtils.newHashMap();
List allFields = TableInfoHelper.getAllFields(resultEntityClass);
Assert.notNull(allFields, "table can not be find");
Set fieldNames = allFields.stream().collect(Collectors.groupingBy(Field::getName)).keySet();
- info.getTableInfo().getFieldList().forEach(
- i -> {
- if (fieldNames.contains(i.getProperty())) {
- set.add(i.getColumn());
- }
- });
+ for (Class> entityClass : sourceEntityClass) {
+ Set set = new HashSet<>();
+ MPJTableInfo info = MPJTableInfoHelper.getTableInfo(entityClass);
+ Assert.notNull(info, "table can not be find");
+ info.getTableInfo().getFieldList().forEach(
+ i -> {
+ if (fieldNames.contains(i.getProperty())) {
+ set.add(i.getColumn());
+ }
+ });
+ maps.put(entityClass.getName(), set);
+ }
/* 添加缓存 */
- VO_INFO_CACHE.put(resultEntityClass, set);
+ VO_INFO_CACHE.put(resultEntityClass, maps);
}
return VO_INFO_CACHE.get(resultEntityClass);
}
diff --git a/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java b/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java
index 539415d..95bcbea 100644
--- a/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java
+++ b/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java
@@ -139,12 +139,13 @@ public class MPJLambdaWrapper extends MPJAbstractLambdaWrapper MPJLambdaWrapper selectAsClass(Class sourceEntityClass, Class> resultEntityClass) {
- TableInfo info = TableInfoHelper.getTableInfo(sourceEntityClass);
- Assert.notNull(info, "table can not be find");
- Set voTableInfo = MPJResultHelper.getVoTableInfo(sourceEntityClass, resultEntityClass);
- Assert.notNull(info, "table can not be find");
- voTableInfo.forEach(i -> selectColumns.add(SelectColumn.of(sourceEntityClass, i)));
+ public MPJLambdaWrapper selectAsClass(Class> resultEntityClass, Class>... sourceEntityClass) {
+ Map> voTableInfo = MPJResultHelper.getVoTableInfo(resultEntityClass, sourceEntityClass);
+ Assert.notNull(voTableInfo, "table can not be find");
+ for (Class> entityClass : sourceEntityClass) {
+ Set columns = voTableInfo.get(entityClass.getName());
+ columns.forEach(i -> selectColumns.add(SelectColumn.of(entityClass, i)));
+ }
return typedThis;
}