Rod*_*sta 0 mongodb kotlin spring-boot
我正在尝试在我的文档中添加一个唯一的复合键,如下所示:
@Document
@CompoundIndexes({
CompoundIndex(def = "{'firstName':1, 'lastName':1}", name = "compound_index_1", unique = true)
})
Run Code Online (Sandbox Code Playgroud)
但我收到错误:
An annotation argument must be a compile-time constant.
Run Code Online (Sandbox Code Playgroud)
有谁能够帮助我?
在 Kotlin 中,数组以不同的方式传递给注解。查看kotlinlang 上的文档,你会在底部附近看到这个片段:
// Kotlin 1.2+:
@AnnWithArrayMethod(names = ["abc", "foo", "bar"])
class C
// Older Kotlin versions:
@AnnWithArrayMethod(names = arrayOf("abc", "foo", "bar"))
class D
Run Code Online (Sandbox Code Playgroud)
所以你的花括号在这里不起作用,你需要方括号。
@Document
@CompoundIndexes(value = [
CompoundIndex(def = "{'firstName':1, 'lastName':1}",
name = "compound_index_1", unique = true)
])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
188 次 |
| 最近记录: |