springboot中validator数据校验功能的实现

  public class User {

  @NotNull(message = "{user.id.notnull}",groups = {ValidationGroup01.class,ValidationGroup02.class})

  private Integer id;

  @Size(min = 5,max = 10,message = "{user.username.size}",groups = {ValidationGroup01.class}) // @Size 字符串长度

  private String username;

  @DecimalMin(value = "1",message = "{user.age.min}") // @DecimalMin 数值最小

  @DecimalMax(value = "100",message = "{user.age.max}")

  private Integer age;

  @Email(message = "{user.email.pattern}",groups = {ValidationGroup01.class})

  private String email;

  }