Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
Review what you have learned in the previous chapter
In the last article, we looked at some simple annotations inside the partial Validation component and looked at some code examples.
Here’s what we learned today
@Future
Rule: The current property value must be some later date.
Built-in parameters for annotations:
“Message” : prompt message
Groups: Indicates the owning group. It is an array type. Multiple groups can be set
How to use:
/** * user certificate validity period */ @future (message = "User certificate validity period must be some later date!" ) private Date validDate;Copy the code
@PastOrPresent
Rule: The current property value must be a past date or a current date.
Built-in parameters for annotations:
“Message” : prompt message
Groups: Indicates the owning group. It is an array type. Multiple groups can be set
How to use:
/** * user's last login date */ @pastorPresent (message = "user's last login date must be a past date or current date!" ) private Date loginDate;Copy the code
@Pattern
Rule: Regular expression rule. The current attribute value must meet the rule of the specified regular.
Built-in parameters for annotations:
Regexp: indicates a regular expression
“Message” : prompt message
Groups: Indicates the owning group. It is an array type. Multiple groups can be set
How to use:
/** * private String nickname */ @pattern (regexp = "^A-\d{12}-\d{4}$",message = "\ A-\d{4}$") private String nickname;Copy the code
summary
To summarize what we learned today, regular expression Validation annotations are special. Regular expressions can take the place of many annotations, but the Validation component provides many simple examples. Again, the proof is in the pudding. Try more.