@interface NotNull The annotated element must not be {@code null}.Accepts any type.-------------------- @interface NotEmpty * The annotated element must not be {@code null} nor empty. Supported types are:* <ul>* <li>{@code CharSequence} (lengt…
@NotNull 适用于非空判断 The annotated element must not be {@code null}. CharSequence, Collection, Map 和 Array 对象不能是 null, 但可以是空集(size = 0). @NotEmpty 适用于判断集合非空且有值 The annotated element must not be {@code null} nor empty. Supported CharSequence, Collection,…
1.实体类属性上添加注解规则 如 public class User { @NotBlank private Integer id ; 2.在方法中添加注解@Valid和一个校验结果参数(BindingResult类型) 如 @RequestMapping(value = "/update" ,method = RequestMethod.POST) public String update(@Valid User user ,BindingResult bindingResult){…
1. 三者主要区别如下: @NotEmpty :用于集合类,不能为null,且size>0 @NotNull:不能为null,但可以为empty,没有size的约束 @NotBlank:只用于String,不能为null,且trim()之后size>0 2. 通过查看源码注释如下: @NotEmpty /** * Asserts that the annotated string, collection, map or array is not {@code null} or empty. *…