Skip to content

Commit

Permalink
feat: selectAll(class,...exclude) 查询全部并排除部分字段
Browse files Browse the repository at this point in the history
  • Loading branch information
yulichang committed May 31, 2024
1 parent f249368 commit 9500ff6
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ public MPJLambdaWrapper(T entity, String alias) {
* 不建议直接 new 该实例,使用 JoinWrappers.lambda(UserDO.class)
*/
protected MPJLambdaWrapper(T entity, Class<T> entityClass, SharedString sqlSelect, AtomicInteger paramNameSeq,
Map<String, Object> paramNameValuePairs, MergeSegments mergeSegments, SharedString paramAlias,
SharedString lastSql, SharedString sqlComment, SharedString sqlFirst,
TableList tableList, Integer index, String keyWord, Class<?> joinClass, String tableName,
BiPredicate<Object, IfExistsSqlKeyWordEnum> IfExists) {
Map<String, Object> paramNameValuePairs, MergeSegments mergeSegments, SharedString paramAlias,
SharedString lastSql, SharedString sqlComment, SharedString sqlFirst,
TableList tableList, Integer index, String keyWord, Class<?> joinClass, String tableName,
BiPredicate<Object, IfExistsSqlKeyWordEnum> IfExists) {
super.setEntity(entity);
super.setEntityClass(entityClass);
this.paramNameSeq = paramNameSeq;
Expand Down Expand Up @@ -197,6 +197,30 @@ public MPJLambdaWrapper<T> selectAll(Class<?> clazz) {
return Query.super.selectAll(clazz);
}

/**
* 查询实体类全部字段
*
* @param clazz 查询的实体类
* @param exclude 排除字段
*/
@Override
@SafeVarargs
public final <E> MPJLambdaWrapper<T> selectAll(Class<E> clazz, SFunction<E, ?>... exclude) {
return Query.super.selectAll(clazz, exclude);
}

/**
* 查询实体类全部字段
*
* @param clazz 查询的实体类
* @param exclude 排除字段
*/
@Override
@SafeVarargs
public final <E> MPJLambdaWrapper<T> selectAll(Class<E> clazz, String prefix, SFunction<E, ?>... exclude) {
return Query.super.selectAll(clazz, prefix, exclude);
}

/**
* 查询主表全部字段
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -173,6 +172,38 @@ default Children selectAll(Class<?> clazz, String prefix) {
return getChildren();
}

/**
* 查询实体类全部字段
*
* @param clazz 查询的实体类
* @param exclude 排除字段
*/
@SuppressWarnings("unchecked")
default <E> Children selectAll(Class<E> clazz, SFunction<E, ?>... exclude) {
Set<String> 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 <E> Children selectAll(Class<E> clazz, String prefix, SFunction<E, ?>... exclude) {
Set<String> 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 片段
*/
Expand Down

0 comments on commit 9500ff6

Please sign in to comment.