!14 QueryCondition.when(Predicate<T>),修复logic为like时value永远不为空

Merge pull request !14 from 落羽er/main
This commit is contained in:
Michael Yang 2023-04-19 08:02:34 +00:00 committed by Gitee
commit 61e5657078
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -118,7 +118,18 @@ public class QueryCondition implements Serializable {
this.effective = fn.get();
}
public <T> QueryCondition when(Predicate<T> fn){
this.effective = fn.test((T) value);
Object val = this.value;
if (LOGIC_LIKE.equals(logic)) {
String valStr = (String) val;
if (valStr.startsWith("%")) {
valStr = valStr.substring(1);
}
if (valStr.endsWith("%")) {
valStr = valStr.substring(0, valStr.length() - 1);
}
val = valStr;
}
this.effective = fn.test((T) val);
return this;
}