mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
refactor: set QueryColumnBehavior.ignoreFunction type to Predicate
This commit is contained in:
parent
64a81fb092
commit
b4212818a3
@ -1026,9 +1026,9 @@ QueryWrapper query2 = QueryWrapper.create()
|
||||
此时,我们可以通过配置 QueryColumnBehavior 来自定义忽略的值。如下的代码会自动忽略 `null` 和 `空字符串`:
|
||||
|
||||
```java
|
||||
QueryColumnBehavior.setIgnoreFunction(new Function<Object, Boolean>() {
|
||||
QueryColumnBehavior.setIgnoreFunction(new Predicate<Object>() {
|
||||
@Override
|
||||
public Boolean apply(Object o) {
|
||||
public boolean test(Object o) {
|
||||
return "".equals(o);
|
||||
}
|
||||
});
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* @author michael
|
||||
@ -25,7 +25,7 @@ public class QueryColumnBehavior {
|
||||
/**
|
||||
* 自定义全局的自动忽略参数的方法
|
||||
*/
|
||||
private static Function<Object,Boolean> ignoreFunction;
|
||||
private static Predicate<Object> ignoreFunction;
|
||||
|
||||
/**
|
||||
* 是否自动把 in(...) 只有 1 个参数的内容转换为相等 =
|
||||
@ -33,12 +33,11 @@ public class QueryColumnBehavior {
|
||||
private static boolean smartConvertInToEquals = false;
|
||||
|
||||
|
||||
|
||||
public static Function<Object, Boolean> getIgnoreFunction() {
|
||||
public static Predicate<Object> getIgnoreFunction() {
|
||||
return ignoreFunction;
|
||||
}
|
||||
|
||||
public static void setIgnoreFunction(Function<Object, Boolean> ignoreFunction) {
|
||||
public static void setIgnoreFunction(Predicate<Object> ignoreFunction) {
|
||||
QueryColumnBehavior.ignoreFunction = ignoreFunction;
|
||||
}
|
||||
|
||||
@ -55,7 +54,7 @@ public class QueryColumnBehavior {
|
||||
if (ignoreFunction == null){
|
||||
return false;
|
||||
}
|
||||
return ignoreFunction.apply(value);
|
||||
return ignoreFunction.test(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user