Springboot Data validation

Source: Internet
Author: User
Tags email string

Can't believe that any data coming from the front end must not trust any data that comes from the front end. Never trust any data from the front end.@JsonFormat time must be in the specified format (here is the format of the receive parameter, not the data to be formatted)
 @Null must be empty @NOtNUll cannot be empty @AssertTrue The Boolean value must be True @AssertFalse The Boolean value must be false @Past Time is the past time (for example, now is 2018-08-12 15:43:23, if the value passed after this time error) @Feauture time is the future time @NotBlank string cannot be null, and the length is greater than 0 @ The email string must be a mailbox @NotEmpty string must be non-empty @Min (10) number must be greater than or equal to @Max (20) number must be less than or equal to @Size (Min=1, max=10) The element range is 1-10 (can be string, array, collection, MAP, etc.) @Length (Min=1, max=10) string length range between 1-10 @Pattern (regexp = "0[0123]") can only be 00 or 01 or 02 or 03
@Valid cascading annotations (if the current property is a JavaBean, the fields inside the bean are also validated)
Note: When the controller layer method receives parameters, the @Valid annotations are used to indicate that the parameters of the current method need to be validated

Each validation note can be added with the message property, prompting the user when the validation failsExample:
// Verify Mailbox
@Email (message= "entered mailbox format is incorrect")private String concatemail; // images This List cannot be null, but each Image is hard to say, see @Valid cascading validation rules @NotNull Private list< @Valid image> images;
// list length is at least 1, cannot be null, each element (String) cannot be null, minimum length @NotNull @size (min=1) Private list< @Size (min=10) @NotNull string> list;

Springboot Data validation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.