spring boot -表单校验步骤 +@NotEmpty,@NotNull和@NotBlank的区别

  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){
  if (bindingResult .hasErrors()) {
    return "/html/edit";
  }

@NotEmpty,@NotNull和@NotBlank的区别
1 @NotEmpty :不能为null,且Size>0 ,不能用于Integer

2  @NotNull:不能为null,但可以为empty,没有Size的约束 Integer可用

3  @NotBlank:只用于String,不能为null且trim()之后size>0 ,不能用于Integer

原文地址:https://www.cnblogs.com/hongchengshise/p/10527757.html