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 index 09003ec..51d6f5a 100644 --- 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 @@ -1,7 +1,7 @@ package com.github.yulichang.toolkit; import java.util.HashMap; -import java.util.Objects; +import java.util.Locale; /** * @author yulichang @@ -12,12 +12,11 @@ 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; + return super.get(((String) key).toUpperCase(Locale.ENGLISH)); + } + + @Override + public boolean containsKey(Object key) { + return super.containsKey(((String) key).toUpperCase(Locale.ENGLISH)); } } \ No newline at end of file diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LambdaUtils.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LambdaUtils.java index 4d12ebe..4b2cffd 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LambdaUtils.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/LambdaUtils.java @@ -2,32 +2,24 @@ package com.github.yulichang.toolkit; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; -import com.github.yulichang.toolkit.support.*; +import com.github.yulichang.toolkit.support.IdeaProxyLambdaMeta; +import com.github.yulichang.toolkit.support.LambdaMeta; +import com.github.yulichang.toolkit.support.ReflectLambdaMeta; +import com.github.yulichang.toolkit.support.ShadowLambdaMeta; import org.apache.ibatis.reflection.property.PropertyNamer; import java.lang.invoke.SerializedLambda; import java.lang.reflect.Method; import java.lang.reflect.Proxy; -import java.util.Map; /** * copy {@link com.baomidou.mybatisplus.core.toolkit.LambdaUtils} */ -@SuppressWarnings("unused") public final class LambdaUtils { public static String getName(SFunction fn) { LambdaMeta extract = extract(fn); - String name = PropertyNamer.methodToProperty(extract.getImplMethodName()); - if (Character.isUpperCase(name.charAt(0))) { - Map map = MPJReflectionKit.getFieldMap(extract.getInstantiatedClass()); - if (map.containsKey(name)) { - return name; - } else { - return map.keySet().stream().filter(i -> i.equalsIgnoreCase(name)).findFirst().orElse(null); - } - } - return name; + return PropertyNamer.methodToProperty(extract.getImplMethodName()); } 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 8c7f477..cfefb68 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 @@ -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(), (o, n) -> n, FieldStringMap::new))); + f.getField().getName().toUpperCase(Locale.ENGLISH), 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 220a503..214e037 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 @@ -9,6 +9,7 @@ import com.github.yulichang.wrapper.segments.SelectCache; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; @@ -43,6 +44,7 @@ public class ColumnCache { 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, FieldStringMap::new))); + i -> i.getColumProperty().toUpperCase(Locale.ENGLISH), + Function.identity(), (i, j) -> j, FieldStringMap::new))); } } diff --git a/mybatis-plus-join-extension/src/main/java/com/github/yulichang/extension/mapping/relation/Relation.java b/mybatis-plus-join-extension/src/main/java/com/github/yulichang/extension/mapping/relation/Relation.java index cda9dca..86375ad 100644 --- a/mybatis-plus-join-extension/src/main/java/com/github/yulichang/extension/mapping/relation/Relation.java +++ b/mybatis-plus-join-extension/src/main/java/com/github/yulichang/extension/mapping/relation/Relation.java @@ -11,10 +11,7 @@ import com.github.yulichang.extension.mapping.mapper.MPJTableInfoHelper; import com.github.yulichang.extension.mapping.wrapper.MappingQuery; import com.github.yulichang.toolkit.LambdaUtils; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; @SuppressWarnings("unchecked") @@ -80,10 +77,10 @@ public class Relation { MPJTableInfo tableInfo = MPJTableInfoHelper.getTableInfo(entityClass); if (tableInfo.isHasMappingOrField()) { boolean hasProperty = CollectionUtils.isNotEmpty(config.getProperty()); - List listProperty = hasProperty ? config.getProperty().stream().map(LambdaUtils::getName).collect( - Collectors.toList()) : null; + List listProperty = hasProperty ? config.getProperty().stream().map(i -> + LambdaUtils.getName(i).toUpperCase(Locale.ENGLISH)).collect(Collectors.toList()) : null; for (MPJTableFieldInfo fieldInfo : tableInfo.getFieldList()) { - if (!hasProperty || listProperty.contains(fieldInfo.getProperty())) { + if (!hasProperty || listProperty.contains(fieldInfo.getProperty().toUpperCase(Locale.ENGLISH))) { List itemList = data.stream().map(fieldInfo::thisFieldGet).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(itemList)) { List joinList = MappingQuery.mpjQueryList(fieldInfo.getJoinMapper(), SqlKeyword.IN, diff --git a/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/entity/AreaDO.java b/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/entity/AreaDO.java index fcc3272..ca6252b 100644 --- a/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/entity/AreaDO.java +++ b/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/test/join/entity/AreaDO.java @@ -26,7 +26,7 @@ public class AreaDO implements Serializable { private String area; - private String postcode; + private String Postcode; @TableLogic private Boolean del; diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/FieldNameTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/FieldNameTest.java new file mode 100644 index 0000000..1ac9467 --- /dev/null +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/m/FieldNameTest.java @@ -0,0 +1,47 @@ +package com.github.yulichang.test.join.m; + +import com.github.yulichang.test.join.dto.AreaDTO; +import com.github.yulichang.test.join.entity.AreaDO; +import com.github.yulichang.test.join.entity.UserDto; +import com.github.yulichang.test.join.mapper.AreaMapper; +import com.github.yulichang.test.util.Reset; +import com.github.yulichang.toolkit.JoinWrappers; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.List; + +@SpringBootTest +public class FieldNameTest { + + @Autowired + private AreaMapper areaMapper; + + @BeforeEach + void setUp() { + Reset.reset(); + } + + + @Test + void testFieldName() { + List list = areaMapper.selectJoinList(AreaDO.class, JoinWrappers.lambda(AreaDO.class) + .select(AreaDO::getPostcode) + .leftJoin(UserDto.class,UserDto::getId,AreaDO::getId)); + + list.forEach(System.out::println); + assert list.get(0).getPostcode() != null; + } + + @Test + void testFieldName1() { + List list = areaMapper.selectJoinList(AreaDTO.class, JoinWrappers.lambda(AreaDO.class) + .selectAs(AreaDO::getPostcode,AreaDTO::getPostcode) + .leftJoin(UserDto.class,UserDto::getId,AreaDO::getId)); + + list.forEach(System.out::println); + assert list.get(0).getPostcode() != null; + } +}