How to get Form validation result in Spring Boot
Form
@Data public class SampleForm { @NotBlank @Size(max=100) private String str; }
When BindingResult is declared as an argument of Controller method and the return value of hasErrors method is true This means that a Form validation error has occurred.
Controller
@Controller
public class SampleController {
@RequestMapping(value = "/Sample", method = RequestMethod.POST)
public String sample(@Validated @ModelAttribute SampleForm form, BindingResult bindingResult, Model model) {
if (bindingResult.hasErrors()) {
List
return "sampleHtml"; } } }
Recommended Posts