春季启动 - 更新数据
我有一个小问题。 我尝试在存储库中更新一列。
存储库
@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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查询方法通过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.