다음 중첩 객체가 있습니다. 컨트롤러에서 유효성 검사를 위해 @Valid를 사용하고 있습니다. 여기서 BindingResult 객체는 Child 객체의 이름 필드의 유효성을 검사하지 않습니다. 내가 놓친 게 있니?스프링 MVC 3 중첩 된 객체 유효성 검사가 @Valid로 실패했습니다
class Parent{
@Valid
private Child child;
//getter and setter for child object
}
class Child{
@NotNull(messag="Name cannot be null")
private String name;
//getter and setter for name
}
My controller validate method
@RequestMapping(value = "/validate", method = RequestMethod.POST)
public @ResponseBody String validate(@Valid @ModelAttribute("parent") Parent parent, BindingResult bindingResult) {
//Here I can see child name value if I say parent.getChild().getName()
// But if parent.getChild().getName() is null, bindingResult.hasErrors() is returning false
}