Hi!
CRUD repo should have update operations, but there is only CUD. There is only "save" for update, should I use it?
Actually, I have next flow. In my Spring MVC Application I have edit method, it looks like
But I completely dislike setting id. I think this is common usage of Spring MVC and Spring Data. Also I want to handle case which deleting user during editing. How I should solve such issue?Code:@RequestMapping(value = "/{id}", method = RequestMethod.POST) public String edit(@PathVariable("id") Long id, @Valid User user, BindingResult bindingResult) { if (bindingResult.hasErrors()) { user.setId(id); //Very bad return "usersEdit"; } user.setId(id); //Bad repository.save(user); return "redirect:/users/" + id; }


Reply With Quote
