验证注解

@NotNull(message = "ID不能为空")
@Range(min = 1, max = 100, message = "ID必须在1到100之间")
private Integer id;

@NotNull(message = "姓名不能为空")
@Length(min = 2, max = 6, message = "姓名必须在2到6位之间")
private String name;

@NotNull(message = "余额不能为空")
@DecimalMax(value = "30.50", message = "余额不能超过30.5")
@DecimalMin(value = "1.50", message = "余额不能低于1.5")
private BigDecimal amount;

@NotNull(message = "生日不能为空")
@Past(message = "生日必须是过去")
private Date birthday;

@NotBlank(message = "邮箱不能为空")
@Email(message = "邮箱格式不正确")
private String email;

@NotBlank(message = "手机号不能为空")
@Pattern(regexp = "^(((13[0-9])|(14[579])|(15([0-3]|[5-9]))|(16[6])|(17[0135678])|(18[0-9])|(19[89]))\\d{8})$", message = "手机号格式错误")
private String phone;
@MobilePattern(message = "手机号不为空")
private String mobile;

posted @ 2022-03-11 11:18  A汉克先生  阅读(63)  评论(0编辑  收藏  举报