@valid校验对象中的对象的对象等

2023-02-05 08:39:41
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才会生效

  • 作者:this is 小疯子
  • 原文链接:https://blog.csdn.net/zengqifeng1997/article/details/102727962
    更新时间:2023-02-05 08:39:41