@Valid只有和 @RequestBody注解一起使用时才生效,且不能时get请求
@Valid和@Validated的区别是前者会嵌套校验,前者是Javax的注解,后者是Spring框架里的注解
如果get请求也想用@size这种校验注解,需要在类上加@Validated
代码如下所示
@RequestMapping("/inboundjavaprocess/portal")
@Validated
public interface PortalApi {
@PostMapping(value = "/portalReceiptSnNo")
ResultDTO test2(@Valid @RequestBody PortalReceiptSnNoRequestDTO portalReceiptSnNoRequestDTO);
@GetMapping(value = "/portalgetinboundorderlist")
ResultDTO test1(
@RequestParam("company_code") String componyCode,
@Size(max = 50) @RequestParam("erp_order_no_list") List<String> erpOrderNoList);
}