英文:
Use @Query to update table in Spring
问题
我正尝试在Spring中使用自定义查询来更新表,但是我遇到了404 NOT FOUND错误。
这是我的repository查询:
@Modifying
@Query("update AssignedFault af set af.userAssigned= :email where af.id= :id")
void allocateFault(@Param("email") String email, @Param("id") Long id);
这是我的controller方法:
@PutMapping("/assigned_faults/assign/{email}/{id}")
void assignFault(@PathVariable String email, @PathVariable Long id){
assignedFaultRepository.allocateFault(email, id);
}
英文:
I am trying to update a table using a custom Query in Spring but I get a 404 NOT FOUND error
Here is my repository query
@Modifying
@Query("update AssignedFault af set af.userAssigned= :email where af.id= :id")
void allocateFault(@Param("email") String email, @Param("id") Long id);
Here is my controller method
@PutMapping("/assigned_faults/assign/{email}/{id}")
void assignFault(@PathVariable String email, @PathVariable Long id){
assignedFaultRepository.allocateFault(email, id);
}
答案1
得分: 0
除了修复方法代码如下所示...
@PutMapping("/assigned_faults/assign")
void assignFault(@RequestParam String email, @RequestParam Long id){
assignedFaultRepository.allocateFault(email, id);
}
...我还在我的存储库接口中添加了 @Transactional 注解。
英文:
On top of fixing the method code like this...
@PutMapping("/assigned_faults/assign")
void assignFault(@RequestParam String email, @RequestParam Long id){
assignedFaultRepository.allocateFault(email, id);
}
... I also added the @Transactional annotation to my repository interface
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论