javax. Validation value list?

Is there any way to use javax Validation to validate variables of color type that need to use only the values of comments (red, blue, green, pink)?

I've seen @ size (min = 1, max = 25) and @ notnull, but there's something like @ in (red, pink)

More or less similar to the "in" keyword used in MySQL

Solution

In this case, I think it would be easier to use the @ pattern annotation, just like the following code snippet If you want a case insensitive assessment, just add the appropriate flag:

@Pattern(regexp =“red | blue | green | pink”,flags = Pattern.Flag.CASE_INSENSITIVE)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>