feat: selectAll(class,...exclude) 查询全部并排除部分字段

This commit is contained in:
yulichang 2024-06-01 06:36:15 +08:00
parent f249368ba7
commit 9500ff6d66
2 changed files with 61 additions and 6 deletions

View File

@ -197,6 +197,30 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
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>

View File

@ -16,8 +16,7 @@ import com.github.yulichang.wrapper.enums.DefaultFuncEnum;
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 @@ public interface Query<Children> extends Serializable {
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 片段
*/