public class A { @NotEmpty(message="name can't be empty") private String name; @NotEmpty(message="id can't be empty") private Long id; }
public class B { @NotEmpty(message = "aList can't be empty") private List<@Valid A> aList; }
public class C { @NotNull(message = "a can't be empty") @Valid private A a; }
@Validated @RestController @RequestMapping("/xxx/") public class XXXController {}
@PostMapping("yyy") public Result<Void> testValidator(@Valid @RequestBody List<A> params){}
@Validated @RestController @RequestMapping("/xxx/") public class XXXController {}
@PostMapping("yyy") public Result<Void> testValidator(@Valid @Validated @RequestBody B b){}
@NotEmpty(message = "aList can't be empty") private List<@Valid A> aList; // 或者 @NotEmpty(message = "aList can't be empty") @Valid private List<A> aList;
@Validated @RestController @RequestMapping("/xxx/") public class XXXController {}
@PostMapping("yyy") public Result<Void> testValidator(@Valid @Validated @RequestBody C c){}
@NotNull(message = "a can't be empty") @Valid private A a;
Tip:@Valid 的使用和 @Validated 的分组功能不冲突,正常使用 group 属性集合