From 261538bdeaca1802e8c45207f6b88c79d7847e00 Mon Sep 17 00:00:00 2001 From: kamosama <837080904@qq.com> Date: Tue, 2 Jul 2024 14:43:22 +0800 Subject: [PATCH 1/4] =?UTF-8?q?doc:=20=E6=9B=B4=E6=96=B0use-in-kotlin.md?= =?UTF-8?q?=E5=AF=B9=E4=BA=8E=E6=8F=92=E4=BB=B6=E9=85=8D=E7=BD=AE=E3=80=81?= =?UTF-8?q?=E6=BC=94=E7=A4=BA=E7=A4=BA=E4=BE=8B=E7=AD=89=E6=8F=90=E9=86=92?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/intro/use-in-kotlin.md | 39 ++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/docs/zh/intro/use-in-kotlin.md b/docs/zh/intro/use-in-kotlin.md index 3a1127a3..84491e15 100644 --- a/docs/zh/intro/use-in-kotlin.md +++ b/docs/zh/intro/use-in-kotlin.md @@ -2,12 +2,10 @@ **MyBatis-Flex-Kotlin 基于 Mybatis-Flex 的 Kotlin 扩展模块,方便 Kotlin 开发者使用 MyBatis-Flex 进行开发。** +> 它继承了 Mybatis-Flex 轻量的特性,同时拥有 Kotlin 特有的扩展方法、中缀表达式与DSL等语法支持, +> 使其拥有了更高的灵活性。让我们可以更加轻松的在 Kotlin 中使用 MyBatis-Flex 所带来的开发效率和开发体验。 ->它继承了 Mybatis-Flex 轻量的特性,同时拥有 Kotlin 特有的扩展方法、中缀表达式与DSL等语法支持, ->使其拥有了更高的灵活性。让我们可以更加轻松的在 Kotlin 中使用 Mybaits-Flex 所带来的开发效率和开发体验。 - -* [Gitee](https://gitee.com/mybatis-flex/mybatis-flex-kotlin) -* [Github](https://github.com/KAMO030/MyBatis-Flex-Kotlin) +### [查看最新版本](https://central.sonatype.com/search?q=mybatis-flex-kotlin) ## 特征 @@ -18,22 +16,25 @@ ## 亮点 - 快速构建启动:通过DSL➕重载运算符,快速配置 MybatisFlexBootstrap 实例并启动: - ```kotlin - runFlex { - // 配置数据源 相当于 setDataSource(dataSource) - +dataSource - // 配置Mapper 相当于 addMapper(AccountMapper::class.java) - +AccountMapper::class - // 配置日志输出 相当于 setLogImpl(StdOutImpl::class.java) - logImpl = StdOutImpl::class - } - ``` + > ⚠️ SpringBoot环境中无需通过此方式配置,请参考[mybatis-flex-spring-boot](https://mybatis-flex.com/zh/base/configuration.html)进行配置 + ```kotlin + runFlex { + // 配置数据源 相当于 setDataSource(dataSource) + +dataSource + // 配置Mapper 相当于 addMapper(AccountMapper::class.java) + +AccountMapper::class + // 配置日志输出 相当于 setLogImpl(StdOutImpl::class.java) + logImpl = StdOutImpl::class + } + ``` - 快速查询数据:通过DSL➕泛型快速编写查询语句并查询: (快速查询提供三个函数:all, filter 和 query ) >- `all<实体类>()` 查泛型对应的表的所有数据 >- `filter<实体类>(vararg KProperty<*>, ()->QueryCondition)` 按条件查泛型对应的表的数据 >- `query<实体类>(QueryScope.()->Unit)` 较复杂查泛型对应的表的数据 (如: 分组,排序等) >- `paginateWith(pageNumber: Number, pageSize: Number, totalRow: Number? = null, queryConditionGet: () -> QueryCondition): Page<实体类>` - 与 `paginate(pageNumber: Number, pageSize: Number, totalRow: Number? = null, init: QueryScope.() -> Unit): Page<实体类>` 使用分页的条件查询与较复杂查询 + 与 `paginate(pageNumber: Number, pageSize: Number, totalRow: Number? = null, init: QueryScope.() -> Unit): Page<实体类>` + 使用分页的条件查询与较复杂查询 + - 简明地构建查询:通过中缀表达式➕扩展方法能更加简单明了的构建条件: * **【对比原生】** @@ -97,8 +98,9 @@ > > 而如果写成String:`Account::age between ("17" to "19")`则会报错提醒 + ## 总结 -引入 Mybatis-Flex-Kotlin 扩展模块在 Kotlin 中使用 Mybaits-Flex 能够基于 Kotlin 强大的语法特性可以让我们更加轻松方便地操作数据库,极大提高了开发效率和开发体验。 +引入 Mybatis-Flex-Kotlin 扩展模块在 Kotlin 中使用 Mybatis-Flex 能够基于 Kotlin 强大的语法特性可以让我们更加轻松方便地操作数据库,极大提高了开发效率和开发体验。 ## 快速开始 @@ -109,6 +111,7 @@ ## 更多使用 - 功能 1:[Bootstrap简化配置](https://gitee.com/mybatis-flex/mybatis-flex-kotlin/blob/main/docs/bootstrapExt.md) -- 功能 2:[简单查询与扩展](https://gitee.com/mybatis-flex/mybatis-flex-kotlin/blob/main/docs/extensions.md) +- 功能 2:[简单查询与扩展](https://gitee.com/mybatis-flex/mybatis-flex-kotlin/blob/main/docs/extensions.md)、[演示示例](https://gitee.com/mybatis-flex/mybatis-flex-kotlin/blob/main/mybatis-flex-kotlin-extensions/src/test/kotlin/example/KotlinExample.kt) - 功能 3:[向量查询](https://gitee.com/mybatis-flex/mybatis-flex-kotlin/blob/main/docs/vec.md) (实验性) - 功能 4:[KSP](https://gitee.com/mybatis-flex/mybatis-flex-kotlin/blob/main/docs/ksp.md) +- 功能 5:[KotlinGradle 插件](https://gitee.com/mybatis-flex/mybatis-flex-kotlin/blob/main/docs/kotlinGradlePlugin.md) From 4e4556e776cc5d098c26090636d7083076b273de Mon Sep 17 00:00:00 2001 From: kamosama <837080904@qq.com> Date: Tue, 2 Jul 2024 14:45:36 +0800 Subject: [PATCH 2/4] =?UTF-8?q?doc:=20=E6=9B=B4=E6=96=B0use-in-kotlin.md?= =?UTF-8?q?=E8=A1=A5=E5=85=85=E9=A1=B9=E7=9B=AE=E9=93=BE=E6=8E=A5=E6=8F=8F?= =?UTF-8?q?=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/intro/use-in-kotlin.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/zh/intro/use-in-kotlin.md b/docs/zh/intro/use-in-kotlin.md index 84491e15..e1d25a0b 100644 --- a/docs/zh/intro/use-in-kotlin.md +++ b/docs/zh/intro/use-in-kotlin.md @@ -5,6 +5,9 @@ > 它继承了 Mybatis-Flex 轻量的特性,同时拥有 Kotlin 特有的扩展方法、中缀表达式与DSL等语法支持, > 使其拥有了更高的灵活性。让我们可以更加轻松的在 Kotlin 中使用 MyBatis-Flex 所带来的开发效率和开发体验。 +* [Gitee](https://gitee.com/mybatis-flex/mybatis-flex-kotlin) +* [Github](https://github.com/KAMO030/MyBatis-Flex-Kotlin) + ### [查看最新版本](https://central.sonatype.com/search?q=mybatis-flex-kotlin) ## 特征 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 3/4] =?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); + } + } From 8a21cf48d0c7e2ffc2c3de2f0cc663da46aa5dad Mon Sep 17 00:00:00 2001 From: kamosama <837080904@qq.com> Date: Fri, 5 Jul 2024 10:58:51 +0800 Subject: [PATCH 4/4] =?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(=E6=B7=BB=E5=8A=A0=E5=AF=B9orderBys=E5=88=A4?= =?UTF-8?q?=E7=A9=BA)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/mybatisflex/core/query/QueryWrapper.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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 2d5ca073..4896210b 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 @@ -2352,10 +2352,12 @@ 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()); + if (CollectionUtil.isNotEmpty(orderBys)) { + for (QueryOrderBy orderBy : orderBys) { + QueryColumn orderByColumn = orderBy.queryColumn; + if (orderByColumn != null && orderByColumn instanceof HasParamsColumn) { + paramValues = ArrayUtil.concat(paramValues, ((HasParamsColumn) orderByColumn).getParamValues()); + } } }