Да, это все форма:
<form th:action="@{/editprofile/save}" th:object="${user}" method="post">
<div class="form-group row">
<label for="name"
class="col-sm-2 pr-0 pl-0 text-center col-form-label">Imię: </label>
<div class="col-sm-10 cl-input">
<input type="text" class="form-control form-text" th:field="*{name}" id="name">
<!--<div class="text col-sm-12 error" th:if="${#fields.hasErrors('name')}"-->
<!--th:errors="*{name}"></div>-->
</div>
</div>
<div class="form-group row">
<label for="surname"
class="col-sm-2 pr-0 pl-0 text-center col-form-label">Nazwisko: </label>
<div class="col-sm-10 cl-input">
<input type="text" class="form-control form-text " th:field="*{surname}" id="surname">
<div class="text col-sm-12 error" th:if="${#fields.hasErrors('surname')}"
th:errors="*{surname}"></div>
</div>
</div>
<div class="form-group row">
<label for="email" class="col-sm-2 pr-0 pl-0 text-center col-form-label">Adres
Email: </label>
<div class="col-sm-10 cl-input">
<input type="email" class="form-control form-text " th:field="*{email}" id="email">
<div class="text col-sm-12 error" th:if="${#fields.hasErrors('email')}"
th:errors="*{email}"></div>
</div>
</div>
<div class="form-group row">
<label for="password"
class="col-sm-2 pr-0 pl-0 text-center hidden col-form-label">Hasło: </label>
<div class="col-sm-10 cl-input">
<input type="text" class="form-control form-text " value="elko" th:value="${user.getPassword()}" th:name="password" id="password">
<!--<div class="text col-sm-12 error" th:if="${#fields.hasErrors('password')}"-->
<!--th:errors="*{password}">-->
<!--</div>-->
</div>
</div>
<div class="form-group row">
<label for="repassword" class="col-sm-2 pr-0 pl-0 text-center col-form-label">Powtórz
Hasło: </label>
<div class="col-sm-10 cl-input">
<input type="text" class="form-control form-text " th:value="${user.getRepassword()}" th:name="repassword" id="repassword">
<!--<div class="text col-sm-12 error" th:if="${#fields.hasErrors('repassword')}"-->
<!--th:errors="*{repassword}">-->
<!--</div>-->
</div>
</div>
<div class="form-group row">
<label for="surname"
class="col-sm-2 pr-0 pl-0 text-center col-form-label">Płec: </label>
<div class="col-sm-10 cl-input">
<input type="text" class="form-control form-text " th:field="*{gender}" id="gender">
<!--<div class="text col-sm-12 error" th:if="${#fields.hasErrors('surname')}"-->
<!--th:errors="*{surname}"></div>-->
</div>
</div>
<div class="form-group row">
<label for="surname"
class="col-sm-2 pr-0 pl-0 text-center col-form-label">Data urodzenia: </label>
<div class="col-sm-10 cl-input">
<input type="text" class="form-control form-text " th:field="*{birthdate}" id="birthdate">
<!--<div class="text col-sm-12 error" th:if="${#fields.hasErrors('surname')}"-->
<!--th:errors="*{surname}"></div>-->
</div>
</div>
<div class="form-group row">
<label for="surname"
class="col-sm-2 pr-0 pl-0 text-center col-form-label">Waga: </label>
<div class="col-sm-10 cl-input">
<input type="text" class="form-control form-text " th:field="*{weight}" id="weight">
<!--<div class="text col-sm-12 error" th:if="${#fields.hasErrors('surname')}"-->
<!--th:errors="*{surname}"></div>-->
</div>
</div>
<div class="form-group row">
<label for="surname"
class="col-sm-2 pr-0 pl-0 text-center col-form-label">Wzrost: </label>
<div class="col-sm-10 cl-input">
<input type="text" class="form-control form-text " th:field="*{growth}" id="growth">
<!--<div class="text col-sm-12 error" th:if="${#fields.hasErrors('surname')}"-->
<!--th:errors="*{surname}"></div>-->
</div>
</div>
<div class="col-lg-12 ">
<div class="row">
<div class="col-lg-2"></div>
<input type="submit" value="Zapisz" class="col-lg-10 btn btn-primary"/>
</div>
</div>
</form>
И это мой контроллер сохранить:
@GetMapping("/editprofile")
public String editeProfile( Model model, Principal principal) {
String email = principal.getName();
User user = userService.findOne(email);
model.addAttribute("user", user);
return "views/editprofile";
}
@GetMapping("/editprofile/{email}")
public String editProfile( @PathVariable String email, Model model,Principal principal) {
model.addAttribute("user", userService.findOne(email));
return "views/editprofile";
}
@PostMapping("/editprofile/save")
public String save(@Valid User user, BindingResult result, RedirectAttributes redirect) {
if(result.hasErrors()) {
return "views/success";
}
System.out.println(user.getEmail());
System.out.println(user.getPassword());
System.out.println(user.getRepassword());
userService.save(user);
redirect.addFlashAttribute("success", "Saved employee successfully!");
return "redirect:/editprofile";
}
Userservice:
public void save(User user) {
userRepository.save(user);
}