Spring Boot -更新数据



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

@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)

是关于改变状态列"friend"的标志布尔值。

当我启动BE时,控制台显示这个错误:

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'!

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

查询方法通过id更改Conversation数据,这是一个数据。所以它将返回一个Conversation对象。

尝试将"列表"更改为"对话"。

或者,我不太清楚,但是quertymethod的命名规范是存在的,所以试着检查一下。

相关内容

  • 没有找到相关文章

最新更新