1.Controller中的函数参数中的对象参数中的对象变量进行数据校验,在对应的对象变量前添加该@Valid注解即可。
1.1controller类中的接口
@PostMapping("/common")
public String common(@RequestBody @Valid ExtendCommonDTO extendCommonDTO) {
return "";
}
ExtendCommonDTO 类
@Data
@ToString
public class ExtendCommonDTO {
private @Valid RestParams restParams;
@Data
public static class RestParams {
/**
* 请求参数 type
*/
@NotNull(message = "请求的接口类型参数不能为空!")
private Integer type;
/**
* 请求参数 json格式
*/
private String json;
}
}