Springboot校验器
添加依赖
implementation 'org.springframework.boot:spring-boot-starter-validation'
Controller层
@Api(tags = "用户相关接口")
@RestController
@RequestMapping("/user")
@Slf4j
@Validated //注意这个注解
public class UserController {
方法
@ApiOperation(value = "用户登录")
@PostMapping(value = "/modify")
public ApiResponse modifyUser( @RequestBody @Valid RequestUserInfo userInfo) {
log.info(JSON.toJSONString(userInfo));
return ApiResponse.success("提交成功");
}
对象
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RequestUserInfo {
@NotBlank(message = "姓名不能为空")
private String name;
@NotBlank(message = "身份证不能为空")
private String idCardNum;
@NotBlank(message = "出生日期不能为空")
private String birthDay;
}
以上三个缺一不可