我有2个bean如下。学生bean验证很好。但内部bean Address
验证完全没有效果。虽然Address.pincode
没有验证,但验证邮件为studentAddress.pincode Value must be an integer
为什么会这样?好吧,我是春天的新人,请详细解释。提前致谢!
public class Student {
@Size(min=2, max=30)
private String studentName;
@Size(min=3, max=30)
private String studentHobby;
@NotNull
private int studentMobile;
@Past
private Date studentDOB;
private ArrayList<String> studentSkills;
private Address studentAddress;
}
public class Address {
@Size(min=4, max=50)
private String country;
@Size(min=4, max=50)
private String city;
private String street;
private int pincode;
}
答案 0 :(得分:2)
如果您使用的是Hibernate Validator 4.0.0+,则可以进行&#34;级联验证&#34;像这样:
@Valid
private Address studentAddress;