Summary of springboot verification annotations

1.@NotBlank is different from @NotNull

2. The use of @Length length

a. Put it above the attribute of the string type that needs to be verified for length;
@Length(max=12, message="The length of the name does not exceed 12")
private String name;

3. The use of @Pattern regular

/**
 * 限额金额
 */
@Pattern(regexp = RegexConstants.QUOTA_AMOUNT, message = "限制金额格式不正确")
private String quotaAmount;      
//正则表达式
public static final String QUOTA_AMOUNT = "^(([1-9]\\d*)|0)(\\.\\d{1,6})?$"

说明: 
regexp: 指定正则表达式字符串,
message:指定正则不匹配返回的错误信息

Guess you like

Origin blog.csdn.net/wangleisuiqiansuiyue/article/details/109668118