From 461843d1b3a349861c0c9a9e8155fb93344c9ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=BD=E7=BE=BDer?= Date: Wed, 19 Apr 2023 15:56:43 +0800 Subject: [PATCH] =?UTF-8?q?QueryCondition.when(Predicate)=E3=80=82?= =?UTF-8?q?=E8=8B=A5logic=E4=B8=BAlike=E6=97=B6=E5=8E=BB=E9=99=A4=E5=89=8D?= =?UTF-8?q?=E5=90=8E=E7=9A=84%=EF=BC=8C=E5=86=8D=E4=BC=A0=E5=85=A5fn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mybatisflex/core/query/QueryCondition.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryCondition.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryCondition.java index c74bf781..ba08827e 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryCondition.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryCondition.java @@ -118,7 +118,18 @@ public class QueryCondition implements Serializable { this.effective = fn.get(); } public QueryCondition when(Predicate 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; }