From 064c0e3bd2a24927938bc6a97cf492102b29ce07 Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Thu, 16 Nov 2023 01:56:27 +0800 Subject: [PATCH] fix https://github.com/yulichang/mybatis-plus-join/issues/91 --- .../yulichang/toolkit/FieldStringMap.java | 23 +++++++++++++++++++ .../yulichang/toolkit/MPJReflectionKit.java | 4 ++-- .../toolkit/support/ColumnCache.java | 12 ++++++---- 3 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/FieldStringMap.java diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/FieldStringMap.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/FieldStringMap.java new file mode 100644 index 0000000..09003ec --- /dev/null +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/FieldStringMap.java @@ -0,0 +1,23 @@ +package com.github.yulichang.toolkit; + +import java.util.HashMap; +import java.util.Objects; + +/** + * @author yulichang + * @see HashMap + * @since 1.4.7.3 + */ +public class FieldStringMap extends HashMap { + + @Override + public V get(Object key) { + V v = super.get(key); + if (Objects.isNull(v)) { + String k = (String) key; + return entrySet().stream().filter(f -> k.equalsIgnoreCase(f.getKey())).findFirst() + .map(Entry::getValue).orElse(null); + } + return v; + } +} \ No newline at end of file diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MPJReflectionKit.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MPJReflectionKit.java index 3276d5f..8c7f477 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MPJReflectionKit.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MPJReflectionKit.java @@ -22,7 +22,7 @@ import java.util.stream.Collectors; @SuppressWarnings("unused") public final class MPJReflectionKit { - private static final Map, Map> CLASS_FIELD_CACHE = new ConcurrentHashMap<>(); + private static final Map, FieldStringMap> CLASS_FIELD_CACHE = new ConcurrentHashMap<>(); private static final Map, List> CLASS_FIELD_LIST_CACHE = new ConcurrentHashMap<>(); private static final Map EMPTY_MAP = new HashMap<>(); @@ -78,7 +78,7 @@ public final class MPJReflectionKit { */ public static Map getFieldMap(Class clazz) { return CLASS_FIELD_CACHE.computeIfAbsent(clazz, key -> getFieldList(key).stream().collect(Collectors.toMap(f -> - f.getField().getName(), Function.identity()))); + f.getField().getName(), Function.identity(), (o, n) -> n, FieldStringMap::new))); } public static List getFieldList(Class clazz) { diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/ColumnCache.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/ColumnCache.java index e4e09ea..220a503 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/ColumnCache.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/support/ColumnCache.java @@ -3,6 +3,7 @@ package com.github.yulichang.toolkit.support; import com.baomidou.mybatisplus.core.metadata.TableInfo; import com.github.yulichang.config.ConfigProperties; import com.github.yulichang.toolkit.Asserts; +import com.github.yulichang.toolkit.FieldStringMap; import com.github.yulichang.toolkit.TableHelper; import com.github.yulichang.wrapper.segments.SelectCache; @@ -23,7 +24,7 @@ public class ColumnCache { private static final Map, List> LIST_CACHE = new ConcurrentHashMap<>(); - private static final Map, Map> MAP_CACHE = new ConcurrentHashMap<>(); + private static final Map, FieldStringMap> MAP_CACHE = new ConcurrentHashMap<>(); public static List getListField(Class clazz) { return LIST_CACHE.computeIfAbsent(clazz, c -> { @@ -31,14 +32,17 @@ public class ColumnCache { Asserts.hasTable(tableInfo, c); List list = new ArrayList<>(); if (ConfigProperties.tableInfoAdapter.mpjHasPK(tableInfo)) { - list.add(new SelectCache(clazz, true, tableInfo.getKeyColumn(), tableInfo.getKeyType(), tableInfo.getKeyProperty(), null)); + list.add(new SelectCache(clazz, true, tableInfo.getKeyColumn(), tableInfo.getKeyType(), + tableInfo.getKeyProperty(), null)); } - list.addAll(tableInfo.getFieldList().stream().map(f -> new SelectCache(clazz, false, f.getColumn(), f.getPropertyType(), f.getProperty(), f)).collect(Collectors.toList())); + list.addAll(tableInfo.getFieldList().stream().map(f -> new SelectCache(clazz, false, f.getColumn(), + f.getPropertyType(), f.getProperty(), f)).collect(Collectors.toList())); return list; }); } public static Map getMapField(Class clazz) { - return MAP_CACHE.computeIfAbsent(clazz, c -> getListField(c).stream().collect(Collectors.toMap(SelectCache::getColumProperty, Function.identity(), (i, j) -> j))); + return MAP_CACHE.computeIfAbsent(clazz, c -> getListField(c).stream().collect(Collectors.toMap( + SelectCache::getColumProperty, Function.identity(), (i, j) -> j, FieldStringMap::new))); } }