QueryCondition.when(Predicate<T>)。若logic为like时去除前后的%,再传入fn

This commit is contained in:
落羽er 2023-04-19 15:56:43 +08:00
parent 8d4a68f558
commit 461843d1b3

View File

@ -118,7 +118,18 @@ public class QueryCondition implements Serializable {
this.effective = fn.get(); this.effective = fn.get();
} }
public <T> QueryCondition when(Predicate<T> fn){ 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; return this;
} }