Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

How to integrate in SpringBoot project

In the last article, we wrote about how to integrate Validation into a Springboot project and how to use it simply.

Springboot project integration parameter verification

Today we’ll look at some basic annotations for the Validation component.

What are the annotations for Validation?

The following code uses user.java as an example.

@NotNull

Rule: The current attribute value cannot be Null. It is recommended to modify values of the Date and Integer types.

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:

/** * userId */ @notblank (groups= {user01. class, user02.class}, message = "userId mandatory ") private String userId;Copy the code

@NotBlank

Rule: The current value of an attribute cannot be empty. It must be content, such as String. It cannot be an empty String and must have a certain value.

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:

/** * username */ @notblank (message = "username mandatory ") private String username;Copy the code

@Null

Rule: The current property value must be Null.

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 password */ @null (message = "user password cannot be directly sent ") private String password;Copy the code

@Past

Rule: The current attribute value must be a past 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 birthday */ @past (message = "user birthday must be a Past date!" ) private Date birthDate;Copy the code

summary

Let’s summarize what we learned today. In fact, we usually use NotNull and NotBlank, which are the basis of our basic effect. So have you learned anything?