Передача данных из формы Spring
У меня есть форма, в которой th:object не находит нужный объект и подсвечен красным, из-за чего передача данных и не работает. В чем может быть ошибка?
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org"
xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity3" lang="en">
<head>
<title>Registration</title>
</head>
<body>
<form action="#" th:action="@{/register}" th:object="${registrationRequest}" method="post">
<div><label> Email : <input type="text" th:field="*{login}" name="login"/> </label></div>
<div><label> Password: <input type="password" th:field="*{password}" name="password"/> </label></div>
<div><input type="submit" value="Sign Up"/></div>
</form>
</body>
</html>
Есть класс RegistrationRequest
@Data
public class RegistrationRequest {
@NotEmpty
private String login;
@NotEmpty
private String password;
}
Есть метод регистрации в контроллере
@PostMapping(value="/register")
public String registerUser(@RequestBody RegistrationRequest registrationRequest) throws UserException {
UserEntity u = new UserEntity();
if(registrationRequest.getLogin()!=null) {
if(registrationRequest.getPassword()!=null) {
u.setPassword(registrationRequest.getPassword());
u.setLogin(registrationRequest.getLogin());
u.setActivationCode(UUID.randomUUID().toString());
userService.saveUser(u);
String message = String.format(
"Hello, %s! \n" +
"Welcome to Sweater. Please, visit next link: http://localhost:8080/activate/%s",
u.getLogin(),
u.getActivationCode()
);
// mailSender.send(u.getLogin(),"Activation code",message);
return "User is created";
}
else throw new UserException("Incorrect password");
}
else throw new UserException("Incorrect login");
}