Код: Выделить всё
@GetMapping("/edit/{id}")
public String editUser(@PathVariable(name = "id") Long id, Model model){
model.addAttribute("userEntity", userService.findById(id));
return "edit";
}
@PutMapping("/edit/{id}")
public UserEntity editUser(@PathVariable(name = "id") Long id) {
return userService.updateUser(id);
}
Код: Выделить всё
public UserEntity updateUser(@RequestParam Long id) {
UserEntity userEntity = userRepo.findById(id).get();
userEntity.setName(userEntity.getName());
userEntity.setPassword(userEntity.getPassword());
return userRepo.save(userEntity);
}
Код: Выделить всё
Edit
New username :
New password:
[url=/]Return to main page[/url]
Пытался смотреть гайды (я новичок в Spring), но у всех так Методы обновления написаны по-другому. И еще я не уверен насчет @PostMapping, нужно ли его добавлять в MainController или нет, если надо, то как
Подробнее здесь: https://stackoverflow.com/questions/787 ... or-has-occ