我可以使用以下注释验证字符串的长度:
@Length(max = 255)
但是如果我想验证长度是 5 还是 9 怎么办?这可以通过注释来完成吗?
我可以使用以下注释验证字符串的长度:
@Length(max = 255)
但是如果我想验证长度是 5 还是 9 怎么办?这可以通过注释来完成吗?
尝试@Pattern(regex=".{5}|.{9}") (如果您不想匹配所有内容,请将点更改为另一个字符类。
这很简单:
所以也许你的注释可能看起来像:
@Constraint(validatedBy=YourChecker.class)
//other annotations
public @interface AllowedValues {
int[] value();
}