|
@@ -4,10 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.Optional;
|
|
|
+import java.util.*;
|
|
|
import java.util.function.Predicate;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -21,13 +18,24 @@ public class WrapperUtil<T> {
|
|
|
|
|
|
private final Predicate<? super Object> ObjPredicate = (Predicate<Object>) Objects::nonNull;
|
|
|
|
|
|
- private final Predicate<? super Object> StrPredicate = (Predicate<Object>) o -> StringUtils.isNotBlank((String) o);
|
|
|
+ private final Predicate<? super String> StrPredicate = (Predicate<String>) StringUtils::isNotBlank;
|
|
|
+
|
|
|
+ private final Predicate<? super Collection<?>> ListPredicate = (Predicate<Collection<?>>) CollectionUtils::isNotEmpty;
|
|
|
|
|
|
public WrapperUtil() {
|
|
|
this.queryWrapper = new QueryWrapper<>();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 返回QueryWrapper
|
|
|
+ *
|
|
|
+ * @return QueryWrapper
|
|
|
+ */
|
|
|
+ public QueryWrapper<T> queryWrapper() {
|
|
|
+ return queryWrapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 值如果不为空则添加到查询条件中
|
|
|
* 仅支持简单的类型
|
|
|
*
|
|
@@ -45,27 +53,25 @@ public class WrapperUtil<T> {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * in 查询
|
|
|
+ * in 查询,值如果不为空则添加到查询条件中
|
|
|
*
|
|
|
* @param column 列名称
|
|
|
- * @param val 逗号分开的值
|
|
|
+ * @param val 集合
|
|
|
*/
|
|
|
- public WrapperUtil<T> hasSplitIn(String column, String val) {
|
|
|
- if (StrPredicate.test(val)) {
|
|
|
- List<String> strings = WrapperUtil.toList(val);
|
|
|
- if (CollectionUtils.isNotEmpty(strings)) {
|
|
|
- queryWrapper.in(column, strings);
|
|
|
- }
|
|
|
- }
|
|
|
+ public WrapperUtil<T> hasIn(String column, Collection<?> val) {
|
|
|
+ queryWrapper.in(ListPredicate.test(val), column, val);
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 返回QueryWrapper
|
|
|
- * @return QueryWrapper
|
|
|
+ * in 查询
|
|
|
+ *
|
|
|
+ * @param column 列名称
|
|
|
+ * @param val 逗号分开的值
|
|
|
*/
|
|
|
- public QueryWrapper<T> queryWrapper() {
|
|
|
- return queryWrapper;
|
|
|
+ public WrapperUtil<T> hasSplitIn(String column, String val) {
|
|
|
+ this.hasIn(column, WrapperUtil.toList(val));
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
public static List<String> toList(String key) {
|