分类 |
限制 |
说明 |
空和非空检查 |
@Null |
限制只能为null |
|
@NotNull |
限制必须不为null |
|
@NotEmpty |
验证注解的元素值不为null且不为空(字符串长度不为0、集合大小不为0) |
|
@NotBlank |
验证注解的元素值不为空(不为null、去除首位空格后长度为0),不同于@NotEmpty,@NotBlank只应用于字符串且在比较时会去除字符串的空格 |
Boolean值得检查 |
@AssertFalse |
限制必须为false |
|
@AssertTrue |
限制必须为true |
长度检查 |
@Size(max,min) |
限制字符长度必须在min到max之间 |
日期检查 |
@Past |
检验日期为当期日期之前 |
|
@Future |
检验日期为当期日期之后 |
|
@PastOrPresent |
校验日期为当前日期或之后 |
数值检查 |
@Max(value) |
限制必须为一个不大于指定值的数字 |
|
@Min(value) |
限制必须为一个不小于指定值的数字 |
|
@DecimalMax(value) |
限制必须为一个不大于指定值的数字 |
|
@DecimalMin(value) |
限制必须为一个不小于指定值的数字 |
|
@Digits(integer,fraction) |
限制必须为一个小数,且整数部分的位数不能超过integer,小数部分的位数不能超过fraction |
|
@Negative |
限制必须为负整数 |
|
@NegativeOrZero |
限制必须为负整数或零 |
|
@Positive |
限制必须为正整数 |
|
@PositiveOrZero |
限制必须为正整数或零 |
其他 |
@Pattern(value) |
限制必须符合指定的正则 |
|
@Email |
限制必须为email |
| |
| |
| |
| |
| |
| |
| @PostMapping("/add") |
| public ResponseEntity<?> add(@RequestBody @Valid AssetImageAndVideoResp rquest, BindingResult bindingResult){ |
| |
| log.info("asset image request params >>> {}", rquest); |
| |
| if (bindingResult.hasErrors()){ |
| throw new BaseException(bindingResult.getFieldError().getDefaultMessage()); |
| } |
| |
| AssetImageJpaEntity assetImageJpaEntity = assetImageService.add(rquest); |
| if (assetImageJpaEntity.getId() != null) { |
| return ResponseEntity.ok(GenericResponse.success()); |
| } else { |
| return ResponseEntity.ok(GenericResponse.error()); |
| } |
| } |
| @Data |
| public class AssetImageAndVideoResp { |
| |
| private int id; |
| |
| @NotBlank(message = "请输入素材url") |
| private String url; |
| |
| @NotBlank(message = "请输入素材名称") |
| private String name; |
| |
| private Integer source; |
| |
| private String advertiserName; |
| private String advertiserId; |
| |
| @Positive(message = "请输入素材宽") |
| private Integer width; |
| |
| @Positive(message = "请输入素材高") |
| private Integer height; |
| |
| private String widthAndHeight; |
| |
| private Integer asceptWidth; |
| |
| private Integer asceptHeight; |
| |
| @Positive(message = "请输入素材大小") |
| private Long size; |
| |
| |
| private Integer assetImageAspectId; |
| |
| private Integer duration; |
| |
| |
| private LocalDateTime createdAt; |
| |
| |
| private LocalDateTime updatedAt; |
| |
| |
| private String createdBy; |
| |
| |
| private String updatedBy; |
| } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)