gpt4 book ai didi

mongodb - 带有Kotlin错误的Spring Data Mongo: “must be a compile-time constant”

转载 作者:行者123 更新时间:2023-12-02 13:09:27 24 4
gpt4 key购买 nike

我试图在我的ReactiveCrudRepository中使用 Kotlin 创建Spring Data Mongo查询:

@Query("{ 'contacts': { $in: ?0 } }")
fun isInContacts(aContact: String): Flux<User>

但是,我收到一个编译错误:
"An annotation parameter must be a compile-time constant"
"Keyword cannot be used as a reference"

如何解决这个问题呢?

它与 $有关吗?由于在字符串中使用它来引用变量?

最佳答案

Does it have something to do with the $. Since its used in Strings to reference a variable?



是的,确实如此,并且 in是Kotlin中的保留字,这就是为什么出现错误 Keyword cannot be used as a reference的原因。您必须转义美元符号以删除其特殊含义:
@Query("{ 'contacts': { \$in: ?0 } }")

关于mongodb - 带有Kotlin错误的Spring Data Mongo: “must be a compile-time constant”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48731916/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com