I have two methods for the button in my MainController
@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);
}
Update method in my UserService
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.html file
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Edit</title>
</head>
<body>
<form th:action="@{/edit}" method="post" th:object="${userEntity}">
<div><label> New username : <input th:field="*{name}" type="text" name="username"/> </label></div>
<div><label> New password: <input th:field="*{password}" type="password" name="password"/> </label></div>
<div><input type="submit" value="Save"></div>
</form>
<a href="/">Return to main page</a>
</body>
</html>
I can not understand in any way why the Whitelabel Error Page error occurs, it does not display an error in the console. On the page he writes There was an unexpected error (type=Not Found, status=404).
I tried to watch the guides (I’m new to Spring), but everyone has Update methods written differently. And I’m also not sure about @PostMapping, whether it needs to be added to the MainController or not, if necessary, how
OGKAZA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.