From 22ad7c4232097c87c714414ffa03059f0eb1725e Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Mon, 17 Jun 2024 19:03:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20isSelect=E5=AF=BC=E8=87=B4=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E6=9F=A5=E8=AF=A2NPE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yulichang/toolkit/support/ColumnCache.java | 7 +++---- .../yulichang/wrapper/interfaces/Query.java | 16 +++++++++------- .../yulichang/wrapper/segments/SelectCache.java | 8 +++++++- 3 files changed, 19 insertions(+), 12 deletions(-) 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 b91658d..2a68c62 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 @@ -1,6 +1,5 @@ package com.github.yulichang.toolkit.support; -import com.baomidou.mybatisplus.core.metadata.TableFieldInfo; import com.baomidou.mybatisplus.core.metadata.TableInfo; import com.github.yulichang.adapter.AdapterHelper; import com.github.yulichang.toolkit.FieldStringMap; @@ -33,10 +32,10 @@ public class ColumnCache { List list = new ArrayList<>(); if (AdapterHelper.getAdapter().mpjHasPK(tableInfo)) { list.add(new SelectCache(clazz, true, tableInfo.getKeyColumn(), tableInfo.getKeyType(), - tableInfo.getKeyProperty(), null)); + tableInfo.getKeyProperty(), true, null)); } - list.addAll(tableInfo.getFieldList().stream().filter(TableFieldInfo::isSelect).map(f -> - new SelectCache(clazz, false, f.getColumn(), f.getPropertyType(), f.getProperty(), f)) + list.addAll(tableInfo.getFieldList().stream().map(f -> + new SelectCache(clazz, false, f.getColumn(), f.getPropertyType(), f.getProperty(), f.isSelect(), f)) .collect(Collectors.toList())); return list; }); diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Query.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Query.java index 03b531b..8dda88e 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Query.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Query.java @@ -52,7 +52,7 @@ public interface Query extends Serializable { default Children select(Class entityClass, Predicate predicate) { TableInfo info = TableHelper.getAssert(entityClass); Map cacheMap = ColumnCache.getMapField(entityClass); - info.getFieldList().stream().filter(predicate).collect(Collectors.toList()).forEach( + info.getFieldList().stream().filter(TableFieldInfo::isSelect).filter(predicate).collect(Collectors.toList()).forEach( i -> getSelectColum().add(new SelectNormal(cacheMap.get(i.getProperty()), getIndex(), isHasAlias(), getAlias()))); return getChildren(); } @@ -71,7 +71,7 @@ public interface Query extends Serializable { default Children selectFilter(Class entityClass, Predicate predicate) { TableInfo info = TableHelper.getAssert(entityClass); List cacheList = ColumnCache.getListField(entityClass); - cacheList.stream().filter(predicate).collect(Collectors.toList()).forEach( + cacheList.stream().filter(SelectCache::isSelect).filter(predicate).collect(Collectors.toList()).forEach( i -> getSelectColum().add(new SelectNormal(i, getIndex(), isHasAlias(), getAlias()))); return getChildren(); } @@ -130,7 +130,9 @@ public interface Query extends Serializable { for (FieldCache cache : fieldList) { if (normalMap.containsKey(cache.getField().getName())) { SelectCache selectCache = normalMap.get(cache.getField().getName()); - getSelectColum().add(new SelectNormal(selectCache, getIndex(), isHasAlias(), getAlias())); + if (selectCache.isSelect()) { + getSelectColum().add(new SelectNormal(selectCache, getIndex(), isHasAlias(), getAlias())); + } } } return getChildren(); @@ -158,7 +160,7 @@ public interface Query extends Serializable { * 查询实体类全部字段 */ default Children selectAll(Class clazz) { - getSelectColum().addAll(ColumnCache.getListField(clazz).stream().map(i -> + getSelectColum().addAll(ColumnCache.getListField(clazz).stream().filter(SelectCache::isSelect).map(i -> new SelectNormal(i, getIndex(), isHasAlias(), getAlias())).collect(Collectors.toList())); return getChildren(); } @@ -167,7 +169,7 @@ public interface Query extends Serializable { * 查询实体类全部字段 */ default Children selectAll(Class clazz, String prefix) { - getSelectColum().addAll(ColumnCache.getListField(clazz).stream().map(i -> + getSelectColum().addAll(ColumnCache.getListField(clazz).stream().filter(SelectCache::isSelect).map(i -> new SelectNormal(i, getIndex(), true, prefix)).collect(Collectors.toList())); return getChildren(); } @@ -182,7 +184,7 @@ public interface Query extends Serializable { default Children selectAll(Class clazz, SFunction... exclude) { Set excludeSet = Arrays.stream(exclude).map(i -> LambdaUtils.getName(i).toUpperCase(Locale.ENGLISH)).collect(Collectors.toSet()); - getSelectColum().addAll(ColumnCache.getListField(clazz).stream().filter(e -> + getSelectColum().addAll(ColumnCache.getListField(clazz).stream().filter(e -> e.isSelect() && !excludeSet.contains(e.getColumProperty().toUpperCase(Locale.ENGLISH))).map(i -> new SelectNormal(i, getIndex(), isHasAlias(), getAlias())).collect(Collectors.toList())); return getChildren(); @@ -198,7 +200,7 @@ public interface Query extends Serializable { default Children selectAll(Class clazz, String prefix, SFunction... exclude) { Set excludeSet = Arrays.stream(exclude).map(i -> LambdaUtils.getName(i).toUpperCase(Locale.ENGLISH)).collect(Collectors.toSet()); - getSelectColum().addAll(ColumnCache.getListField(clazz).stream().filter(e -> + getSelectColum().addAll(ColumnCache.getListField(clazz).stream().filter(e -> e.isSelect() && !excludeSet.contains(e.getColumProperty().toUpperCase(Locale.ENGLISH))).map(e -> new SelectNormal(e, getIndex(), true, prefix)).collect(Collectors.toList())); return getChildren(); diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/segments/SelectCache.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/segments/SelectCache.java index 989f868..ac0c4bf 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/segments/SelectCache.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/segments/SelectCache.java @@ -70,7 +70,12 @@ public class SelectCache { */ private final TypeHandler typeHandler; - public SelectCache(Class clazz, boolean isPk, String column, Class columnType, String columProperty, TableFieldInfo tableFieldInfo) { + /** + * 是否查询 + */ + private final boolean isSelect; + + public SelectCache(Class clazz, boolean isPk, String column, Class columnType, String columProperty, boolean isSelect, TableFieldInfo tableFieldInfo) { this.clazz = clazz; this.isPk = isPk; this.column = column; @@ -78,6 +83,7 @@ public class SelectCache { this.columProperty = columProperty; this.tagColumn = MPJStringUtils.getTargetColumn(column); this.tableFieldInfo = tableFieldInfo; + this.isSelect = isSelect; if (Objects.isNull(tableFieldInfo)) { this.hasTypeHandle = false; this.typeHandler = null;