Kotlin
参考文档的此部分解释了 Spring Data R2DBC 提供的特定 Kotlin 功能。有关 Spring Data 提供的一般功能,请参阅 kotlin.adoc。
This part of the reference documentation explains the specific Kotlin functionality offered by Spring Data R2DBC. See kotlin.adoc for the general functionality provided by Spring Data.
要在 Java 中检索 SWCharacter
对象列表,您通常会编写以下内容:
To retrieve a list of SWCharacter
objects in Java, you would normally write the following:
Flux<SWCharacter> characters = client.select().from(SWCharacter.class).fetch().all();
使用 Kotlin 和 Spring Data 扩展,您可以编写以下内容:
With Kotlin and the Spring Data extensions, you can instead write the following:
val characters = client.select().from<SWCharacter>().fetch().all()
// or (both are equivalent)
val characters : Flux<SWCharacter> = client.select().from().fetch().all()
与 Java 一样,Kotlin 中的 characters
是强类型的,但 Kotlin 的巧妙类型推断允许使用更简洁的语法。
As in Java, characters
in Kotlin is strongly typed, but Kotlin’s clever type inference allows for shorter syntax.
Spring Data R2DBC 提供以下扩展:
Spring Data R2DBC provides the following extensions:
-
Reified generics support for
DatabaseClient
andCriteria
. -
kotlin/coroutines.adoc extensions for
DatabaseClient
.