Я не могу настроить проверку в весеннем проекте.
Класс сущности
Код: Выделить всё
import javax.validation.constraints.*;
public class Employee {
@Size(min = 2,message = "Name must be minimum 2 symbols")
private String name;
@NotEmpty(message = "surname is required field")
private String surname;
}
Класс контроллера
Код: Выделить всё
import javax.validation.Valid;
@Controller
@RequestMapping("/")
public class MyController {
@RequestMapping("/showDetails")
public String showDetails(
@ModelAttribute("employee") @Valid Employee employee,
BindingResult bindingResult, Errors errors){
if(bindingResult.hasErrors()){ // bindingResult.hasErrors() always return false
return "ask-detail-view";
}else{
return "show-detail-view";
}
}
}
Код: Выделить всё
org.hibernate.validator
hibernate-validator
8.0.1.Final
Код: Выделить всё
Name
Surname
Подробнее здесь: https://stackoverflow.com/questions/787 ... t-0-errors