春季启动 - 更新数据

发布于 2025-02-12 13:18:50 字数 2455 浏览 2 评论 0原文

我有一个小问题。 我尝试在存储库中更新一列。

存储库

@Modifying
@Query("UPDATE Conversation conversation SET conversation.friend = ?1 WHERE conversation.id = ?2")
fun setConversationInfoById(friend: Boolean, id: UUID): List<Conversation>

服务

fun addDeleteFriend(conversation: Conversation) {
    val openedConversation = db.findByIdOrNull(conversation.id)

    if (openedConversation == null) db.save(conversation)
    else db.setConversationInfoById(openedConversation.friend, openedConversation.id)
}

控制器

@PostMapping("/friend", consumes = [MediaType.APPLICATION_JSON_VALUE])
        @ResponseBody
        fun friend(@RequestBody conversation: Conversation) = service.addDeleteFriend(conversation)

它是关于标志的 - 布尔人将更改状态列“朋友”。

当我开始时,主机向我展示了一个错误:

    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with
 name 'conversationController' defined in file [####]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
 'conversationService' defined in file [####]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'conversationRepository' defined in com.###.backend.repository.ConversationRepository defined in 
@EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration:
 Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for 
public abstract java.util.List com.###.backend.repository.ConversationRepository.setConversationInfoById(boolean,java.util.UUID)!
 Reason: Failed to create query for method public abstract java.util.List 
com.##.backend.repository.ConversationRepository.setConversationInfoById(boolean,java.util.UUID)!
 No property 'setConversationInfoById' found for type 'Conversation'!; nested exception is 
java.lang.IllegalArgumentException: Failed to create query for method public abstract 
java.util.List com.###.backend.repository.ConversationRepository.setConversationInfoById(boolean,java.util.UUID)!
 No property 'setConversationInfoById' found for type 'Conversation'!

我尝试了所有选项,但是我不知道有什么问题。

I have a little problem.
I try update in repository one column.

Repository

@Modifying
@Query("UPDATE Conversation conversation SET conversation.friend = ?1 WHERE conversation.id = ?2")
fun setConversationInfoById(friend: Boolean, id: UUID): List<Conversation>

Service

fun addDeleteFriend(conversation: Conversation) {
    val openedConversation = db.findByIdOrNull(conversation.id)

    if (openedConversation == null) db.save(conversation)
    else db.setConversationInfoById(openedConversation.friend, openedConversation.id)
}

Controler

@PostMapping("/friend", consumes = [MediaType.APPLICATION_JSON_VALUE])
        @ResponseBody
        fun friend(@RequestBody conversation: Conversation) = service.addDeleteFriend(conversation)

It's about the flag - boolean whos will change status column "friend".

When I'm starting BE the console shows me this error:

    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with
 name 'conversationController' defined in file [####]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
 'conversationService' defined in file [####]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'conversationRepository' defined in com.###.backend.repository.ConversationRepository defined in 
@EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration:
 Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for 
public abstract java.util.List com.###.backend.repository.ConversationRepository.setConversationInfoById(boolean,java.util.UUID)!
 Reason: Failed to create query for method public abstract java.util.List 
com.##.backend.repository.ConversationRepository.setConversationInfoById(boolean,java.util.UUID)!
 No property 'setConversationInfoById' found for type 'Conversation'!; nested exception is 
java.lang.IllegalArgumentException: Failed to create query for method public abstract 
java.util.List com.###.backend.repository.ConversationRepository.setConversationInfoById(boolean,java.util.UUID)!
 No property 'setConversationInfoById' found for type 'Conversation'!

I tried all option, but I don't know what is the problem ..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染年凉城似染瑾 2025-02-19 13:18:50

查询方法通过ID更改对话数据,这是一个数据。
因此,它将返回一个对话对象。

尝试将列表更改为对话。

或者,我不太了解,但是存在Quertymethod命名惯例,因此请尝试查看。

query method changes Conversation data by id, which is one data.
So it will be return one Conversation object.

try to change List to Conversation.

or, I don't know well, but quertymethod naming convention is exist, so try to check out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文