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 previous article, we learned about several additional annotations inside the partial Validation component.

Respectively is the annotation @range of whether the effect attribute value conforms to the current Range;

There are also @AssertFalse and @AssertTrue annotations that validate the current Boolean attribute value;

Of course, we also looked at the relevant code examples, is it not enough to learn, then continue to learn today.

Here’s what we learned today

@Email

Rule: The current attribute value must be within the valid range set by the annotation

Built-in parameters for annotations:

Min: indicates the minimum value

Max: maximum value

“Message” : prompt message

Groups: Indicates the owning group. It is an array type. Multiple groups can be set

How to use:

/ * * * * / @ Email users age (regexp = "*. *", message = "user Email format error." , groups= {User01.class, User02.class}) private String email;Copy the code

@DecimalMax

Rule: The property value must be smaller than the value set in the annotation.

Built-in parameters for annotations:

Value: indicates the parameter value

“Message” : prompt message

Groups: Indicates the owning group. It is an array type. Multiple groups can be set

How to use:

/** * @decimalmax (value=100, message = "User asset error, ", groups= {user01. class, user02.class}) private double zichan;Copy the code

@DecimalMin

Rule: The property value must be greater than the value specified in the annotation.

Built-in parameters for annotations:

Value: indicates the parameter value

“Message” : prompt message

Groups: Indicates the owning group. It is an array type. Multiple groups can be set

How to use:

/** * @decimalmax (value=100, message = "User asset error, ", groups= {user01. class, user02.class}) private double zichan;Copy the code

conclusion

Here we have probably finished the usual commonly used annotations, or to try more, to deepen the memory.