一、@RequestBody配合@Valid使用
@ApiOperation("上报第三方平台物模型关系")
@PostMapping
public ResponseEntity<String> reportModelRel(@RequestBody @Valid PartnerModelRelDto modelRelDto) {
partnerModelRelService.reportModelRel(modelRelDto);
return new ResponseEntity<>("Success", HttpStatus.OK);
}
二、参数接收类中使用注解标注
@NotNull:参数不能为null;
@NotBlank:参数不能为null并且不能为空(比如字符串,不能传个空串"");
@NotEmpty:集合参数不能为null并且不能为空集合;
如果有内部类字段需要判空,则需要在引用内部类的字段上再加一个@Valid注解。
@Data
public class PartnerModelRelDto {
@Data
public static class Property extends AuditDomain {
@ApiModelProperty("第三方平台的功能标识符")
@NotBlank(message = "sid不能为空")
private String sid;
@ApiModelProperty("第三方平台的功能类型")
private String st;
}
@NotNull(message = "id不能为空")
private Integer id;
@ApiModelProperty("第三方平台的productId")
@NotBlank(message = "pidPartner不能为空")
private String pidPartner;
@NotEmpty(message = "propertyList不能为空")
@Valid
List<Property> propertyList;
}