From 9500ff6d66b46c724ec861105032c63f87eea848 Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Sat, 1 Jun 2024 06:36:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20selectAll(class,...exclude)=20=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=85=A8=E9=83=A8=E5=B9=B6=E6=8E=92=E9=99=A4=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yulichang/wrapper/MPJLambdaWrapper.java | 32 ++++++++++++++--- .../yulichang/wrapper/interfaces/Query.java | 35 +++++++++++++++++-- 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java index 867a5ed7..81337ca7 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java @@ -123,10 +123,10 @@ public MPJLambdaWrapper(T entity, String alias) { * 不建议直接 new 该实例,使用 JoinWrappers.lambda(UserDO.class) */ protected MPJLambdaWrapper(T entity, Class entityClass, SharedString sqlSelect, AtomicInteger paramNameSeq, - Map paramNameValuePairs, MergeSegments mergeSegments, SharedString paramAlias, - SharedString lastSql, SharedString sqlComment, SharedString sqlFirst, - TableList tableList, Integer index, String keyWord, Class joinClass, String tableName, - BiPredicate IfExists) { + Map paramNameValuePairs, MergeSegments mergeSegments, SharedString paramAlias, + SharedString lastSql, SharedString sqlComment, SharedString sqlFirst, + TableList tableList, Integer index, String keyWord, Class joinClass, String tableName, + BiPredicate IfExists) { super.setEntity(entity); super.setEntityClass(entityClass); this.paramNameSeq = paramNameSeq; @@ -197,6 +197,30 @@ public MPJLambdaWrapper selectAll(Class clazz) { return Query.super.selectAll(clazz); } + /** + * 查询实体类全部字段 + * + * @param clazz 查询的实体类 + * @param exclude 排除字段 + */ + @Override + @SafeVarargs + public final MPJLambdaWrapper selectAll(Class clazz, SFunction... exclude) { + return Query.super.selectAll(clazz, exclude); + } + + /** + * 查询实体类全部字段 + * + * @param clazz 查询的实体类 + * @param exclude 排除字段 + */ + @Override + @SafeVarargs + public final MPJLambdaWrapper selectAll(Class clazz, String prefix, SFunction... exclude) { + return Query.super.selectAll(clazz, prefix, exclude); + } + /** * 查询主表全部字段 *

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 b096944a..03b531bd 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 @@ -16,8 +16,7 @@ import com.github.yulichang.wrapper.segments.*; import java.io.Serializable; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -173,6 +172,38 @@ default Children selectAll(Class clazz, String prefix) { return getChildren(); } + /** + * 查询实体类全部字段 + * + * @param clazz 查询的实体类 + * @param exclude 排除字段 + */ + @SuppressWarnings("unchecked") + 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 -> + !excludeSet.contains(e.getColumProperty().toUpperCase(Locale.ENGLISH))).map(i -> + new SelectNormal(i, getIndex(), isHasAlias(), getAlias())).collect(Collectors.toList())); + return getChildren(); + } + + /** + * 查询实体类全部字段 + * + * @param clazz 查询的实体类 + * @param exclude 排除字段 + */ + @SuppressWarnings("unchecked") + 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 -> + !excludeSet.contains(e.getColumProperty().toUpperCase(Locale.ENGLISH))).map(e -> + new SelectNormal(e, getIndex(), true, prefix)).collect(Collectors.toList())); + return getChildren(); + } + /** * select sql 片段 */