public Object testOne(@RequestBody @Valid Dto dto) {}
public class Dto {
private Student student;
@Valid
private Teacher teacher;
}
public class Teacher {
@NotNull(message = "教师id不能为空")
private Integer id;
@NotBlank(message = "教师名字不能为空")
private String teacherName;
}
从上至下,都加上@valid,直到我们最终的需要校验的那个对象(其他对象的属性)
如此@Valid才会生效