From 0edf12b05d495235bc879e9d61561ba5baa7ba7c Mon Sep 17 00:00:00 2001 From: kamosama <837080904@qq.com> Date: Fri, 5 Jul 2024 10:26:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3orderBy=E6=97=B6?= =?UTF-8?q?=E4=BC=A0=E5=85=A5=E7=9A=84=E5=8F=98=E9=87=8F=E5=A4=B1=E6=95=88?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mybatisflex/core/query/QueryOrderBy.java | 2 +- .../com/mybatisflex/core/query/QueryWrapper.java | 8 ++++++++ .../com/mybatisflex/coretest/QueryWrapperTest.java | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryOrderBy.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryOrderBy.java index e033ed4a..5110679b 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryOrderBy.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryOrderBy.java @@ -29,7 +29,7 @@ import java.util.List; */ public class QueryOrderBy implements CloneSupport { - private QueryColumn queryColumn; + QueryColumn queryColumn; /** * asc, desc diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryWrapper.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryWrapper.java index 2186f12d..2d5ca073 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryWrapper.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryWrapper.java @@ -2351,6 +2351,14 @@ public class QueryWrapper extends BaseQueryWrapper { Object[] paramValues = ArrayUtil.concat(whereValues, havingValues); + // orderBy 参数 + for (QueryOrderBy orderBy : orderBys) { + QueryColumn orderByColumn = orderBy.queryColumn; + if (orderByColumn != null && orderByColumn instanceof HasParamsColumn) { + paramValues = ArrayUtil.concat(paramValues, ((HasParamsColumn) orderByColumn).getParamValues()); + } + } + // unions 参数 if (CollectionUtil.isNotEmpty(unions)) { for (UnionWrapper union : unions) { diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/QueryWrapperTest.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/QueryWrapperTest.java index 8fe1cff7..658457fb 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/QueryWrapperTest.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/QueryWrapperTest.java @@ -23,6 +23,8 @@ import com.mybatisflex.core.query.QueryWrapper; import org.junit.Assert; import org.junit.Test; +import java.util.Arrays; + import static com.mybatisflex.coretest.table.AccountTableDef.ACCOUNT; import static com.mybatisflex.core.query.QueryMethods.*; @@ -66,4 +68,16 @@ public class QueryWrapperTest { } + @Test + public void testOrderByValue(){ + QueryWrapper wrapper = QueryWrapper.create() + .select("*") + .from(Account.class) + .orderBy(case_() + .when(new QueryColumn("id").in(1, 2, 3)) + .then(1).end().asc() + ); + Assert.assertEquals(CPI.getValueArray(wrapper).length, 3); + } + }