In the SpringBoot project, I validate the form, the get request receives data verification and an error is immediately written.
Controller
@Controller @RequestMapping("registration") public class RegistrationController extends WebMvcConfigurerAdapter { @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("results").setViewName("results"); } @RequestMapping(method = RequestMethod.GET) public String init(RegistrationForm registrationForm) { System.out.println("get"); return "form"; } @RequestMapping(method = RequestMethod.POST) public String checkRegistratioInfo(@Valid RegistrationForm registrationForm, BindingResult bindingResult) { System.out.println("post"); if (bindingResult.hasErrors()) { return "form"; } return "redirect:results"; } form, there are heteras, setters.
public class RegistrationForm { @NotNull(message = "Please enter your login.") @Size(min = 3, max = 20, message = "Your login must between 3 and 20 characters") private String login; @NotNull(message = "Please enter your password.") @Size(min = 5, max = 20, message = "Your password must between 5 and 20 characters") private String password; @NotNull(message = "Please enter your email first name.") @Size(min = 4, max = 20, message = "Your first name must between 4 and 20 characters") private String first_name; @NotNull(message = "Please enter your email last name.") @Size(min = 4, max = 20, message = "Your last name must between 4 and 20 characters") private String last_name; @NotNull(message = "Please enter your email middle name.") @Size(min = 4, max = 20, message = "Your middle name must between 4 and 20 characters") private String middle_name; @NotNull(message = "Please enter your information about yourself") @Size(min = 20, message = "Your information about yourself must be min 20 characters") private String your_info; @NotNull(message = "Please enter your mobile phone.") private Integer mobile_phone; private Integer home_phone; @Size(min = 10, message = "Your address must be min 10 characters") private String address; @Email private String email; html page
<html xmlns:th="http://www.w3.org/1999/xhtml"> <body> <form action="#" th:th:action="@{registration}" th:object="${registrationForm}" method="post"> <table> <tr> <tr class="tg"> <th colspan="2"><h4>Регистрация</h4></th> <tr> <tr> <td>Login:</td> <td><input type="text" th:field="*{login}"/></td> <td th:if="${#fields.hasErrors('login')}" th:errors="*{login}">Name Error</td> </tr> <tr> <td>Пароль:</td> <td><input type="text" th:field="*{password}"/></td> <td th:if="${#fields.hasErrors('password')}" th:errors="*{password}">Name Error</td> </tr> <tr> <td>Имя:</td> <td><input type="text" th:field="*{first_name}"/></td> <td th:if="${#fields.hasErrors('first_name')}" th:errors="*{first_name}">Name Error</td> </tr> <tr> <td>Фамилия:</td> <td><input type="text" th:field="*{last_name}"/></td> <td th:if="${#fields.hasErrors('last_name')}" th:errors="*{last_name}">Name Error</td> </tr> <tr> <td>Отчество:</td> <td><input type="text" th:field="*{middle_name}"/></td> <td th:if="${#fields.hasErrors('middle_name')}" th:errors="*{middle_name}">Name Error</td> </tr> <tr> <td>Информация о Вас:</td> <td><input type="text" th:field="*{your_info}"/></td> <td th:if="${#fields.hasErrors('your_info')}" th:errors="*{your_info}">Name Error</td> </tr> <tr> <td>Мобильный телефон:</td> <td><input type="text" th:field="*{mobile_phone}"/></td> <td th:if="${#fields.hasErrors('mobile_phone')}" th:errors="*{mobile_phone}">Name Error</td> </tr> <tr> <td>Домашний телефон:</td> <td><input type="text" th:field="*{home_phone}"/></td> <td th:if="${#fields.hasErrors('home_phone')}" th:errors="*{home_phone}">Name Error</td> </tr> <tr> <td>Адрес:</td> <td><input type="text" th:field="*{address}"/></td> <td th:if="${#fields.hasErrors('address')}" th:errors="*{address}">Name Error</td> </tr> <tr> <td>Email:</td> <td><input type="email" th:field="*{email}"/></td> <td th:if="${#fields.hasErrors('email')}" th:errors="*{email}">Name Error</td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="Регистрация"></td> </tr> </table> </form> </body> </html> Tell me what needs to be changed so that on the gett the request was a normal page display, did the data check on the post? reference to the project