0
validation-api-1.0.0.GA.jar and hibernate-validator-4.1.0.Final.jar are in classpath. mvc:annotation-driven is in -servlet.xml file.
@RequestMapping(value = "/addEmployee", method = RequestMethod.POST) public ModelAndView addEmployee(@Valid EmployeeDTO employeeDTO, BindingResult result) {
JSR-303 검증은 인용 콘솔 메시지에 따라,
System.out.println("addEmployee employeeDTO! "+ employeeDTO);
System.out.println("result.getErrorCount() "+result.getErrorCount());
}
public class EmployeeDTO {
private int employeeId;
public int getEmployeeId() {
return employeeId;
}
public void setEmployeeId(int employeeId) {
this.employeeId = employeeId;
}
@NotNull
private String firstName;
@NotNull
private String lastName;
private Date hireDate;
}
in the console
addEmployee employeeDTO! EmployeeDTO [employeeId=0, firstName=, lastName=, deptName=null, deptId=0, email=, salary=0, jobId=AD_VP, hireDate=null]
result.getErrorCount() 0
이제 컨트롤러에서 JSR-303 유효성 검사와 함께 사용자 지정 유효성 검사와 결합 할 때 JSR-303 유효성 검사가 작동하지 않습니다. @ InitBinder protected void initBinder (WebDataBinder binder) {binder.registerCustomEditor (String.class, new StringTrimmerEditor 참된)); binder.setValidator (새 EmailValidator());} – user739115