Spring MVC bean验证问题

时间:2014-11-10 08:26:11

标签: java spring validation spring-mvc

我有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;
}

1 个答案:

答案 0 :(得分:2)

如果您使用的是Hibernate Validator 4.0.0+,则可以进行&#34;级联验证&#34;像这样:

@Valid
private Address studentAddress;