<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-validation</artifactId></dependency>
控制器
@Validated 控制器上打@Validated注解
@Valid 实体对象上打@Valid注解
@Validated@Api(tags = "用户配置中心接口")@RestController@RequestMapping("/ucc")public class UccEntityController {@ApiOperation("根据key更新配置信息")@PutMapping("/{key}")public ResultVO updateUccByKey(@ApiParam(value = "主键key", defaultValue = "ALL_CWA6920")@PathVariable("key") String key,@RequestBody @Valid UpdateDTO dto) {return ResultVO.success(uccEntityService.updateUccByKey(key, dto));}}
实体对象
public class UpdateDTO {@NotBlank(message = "唯一键不能为空")@ApiModelProperty(value = "唯一key", example = "ALL_CWA6920")private String key;}
