zl程序教程

您现在的位置是:首页 >  其他

当前栏目

JSR303参数校验知识

2023-03-15 23:27:21 时间

1 依赖

 <dependency>
     <groupId>javax.validation</groupId>
     <artifactId>validation-api</artifactId>
     <version>2.0.1.Final</version>
 </dependency>

2 参数使用

@NotNull:` CharSequence, Collection, Map 和 Array 对象不能是 null, 但可以是空集(size = 0)。 @NotEmpty:` CharSequence, Collection, Map 和 Array 对象不能是 null 并且相关对象的 size 大于 0。 @NotBlank:` String 不是 null 且去除两端空白字符后的长度(trimmed length)大于 0。

3使用(bean前+@Validated)

如果name 修改的时候可以为空,添加的时候不能为空,那么使用分组

 public interface UpdateGroup{

}
@NotBlank(message = "name增加是必须提交",groups = {AddGroup.class})

那使用的时候