miemie пре 6 година
родитељ
комит
4f500dbaac

+ 26 - 31
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/LambdaUtils.java

@@ -79,19 +79,6 @@ public final class LambdaUtils {
         LAMBDA_CACHE.put(clazz.getName(), createLambdaMap(tableInfo, clazz));
     }
 
-    /**
-     * 保存缓存信息
-     *
-     * @param className   类名
-     * @param property    属性
-     * @param columnCache 字段信息
-     */
-    private static void saveCache(String className, String property, ColumnCache columnCache) {
-        Map<String, ColumnCache> cacheMap = LAMBDA_CACHE.getOrDefault(className, new HashMap<>());
-        cacheMap.put(property, columnCache);
-        LAMBDA_CACHE.put(className, cacheMap);
-    }
-
     /**
      * <p>
      * 缓存实体字段 MAP 信息
@@ -104,28 +91,36 @@ public final class LambdaUtils {
         Map<String, ColumnCache> map = new HashMap<>();
         String keyProperty = tableInfo.getKeyProperty();
         if (StringUtils.isNotEmpty(keyProperty)) {
-            keyProperty = keyProperty.toUpperCase(ENGLISH);
-            String keyColumn = tableInfo.getKeyColumn();
-            String keySelect = tableInfo.getSqlSelect();
-            ColumnCache cache = new ColumnCache(keyColumn, keySelect);
-            if (tableInfo.getClazz() != clazz) {
-                saveCache(tableInfo.getClazz().getName(), keyProperty, cache);
-            }
-            map.put(keyProperty, cache);
+            saveCacheAndPut(tableInfo.getKeyColumn(), tableInfo.getSqlSelect(), keyProperty.toUpperCase(ENGLISH),
+                clazz, tableInfo.getClazz(), map);
         }
-        tableInfo.getFieldList().forEach(i -> {
-            String property = i.getProperty().toUpperCase(ENGLISH);
-            String column = i.getColumn();
-            String columnSelect = i.getSqlSelect(tableInfo.getDbType());
-            ColumnCache cache = new ColumnCache(column, columnSelect);
-            if (i.getClazz() != clazz) {
-                saveCache(i.getClazz().getName(), property, cache);
-            }
-            map.put(property, cache);
-        });
+        tableInfo.getFieldList().forEach(i -> saveCacheAndPut(i.getColumn(), i.getSqlSelect(tableInfo.getDbType()),
+            i.getProperty().toUpperCase(ENGLISH), clazz, i.getClazz(), map));
         return map;
     }
 
+    private static void saveCacheAndPut(String column, String select, String property, Class<?> entityClass,
+                                        Class<?> propertyAffiliationClass, Map<String, ColumnCache> map) {
+        ColumnCache cache = new ColumnCache(column, select);
+        if (propertyAffiliationClass != entityClass) {
+            saveCache(propertyAffiliationClass.getName(), property, cache);
+        }
+        map.put(property, cache);
+    }
+
+    /**
+     * 保存缓存信息
+     *
+     * @param className   类名
+     * @param property    属性
+     * @param columnCache 字段信息
+     */
+    private static void saveCache(String className, String property, ColumnCache columnCache) {
+        Map<String, ColumnCache> cacheMap = LAMBDA_CACHE.getOrDefault(className, new HashMap<>());
+        cacheMap.put(property, columnCache);
+        LAMBDA_CACHE.put(className, cacheMap);
+    }
+
     /**
      * <p>
      * 获取实体对应字段 MAP