@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){…
源码解析 @NotEmpty根据JDK源码注释说明,该注解只能应用于char可读序列(可简单理解为String对象),colleaction,map,array上,因为该注解要求的是对象不为null且size>0,所以只有上述对象是拥有size属性的,而Integer,Long等基础对象包装类没有该属性 /** * The annotated element must not be {@code null} nor empty. Supported types are: * <ul> *…