Spring Boot Custom Validator annotations

Source: Internet
Author: User

Spring boot can use @valid to verify when the post accepts an object parameter, as in the following code

When you create a user class

The above @notblank and @past made a judgment on how to do similar annotations to validate the data

To create an Myconstraint interface

@Retention: Used to describe the life cycle of the annotation class. It has the following three parameters:
Retentionpolicy.source: Annotations remain in the source file only
Retentionpolicy.class: Annotations remain in the CLASS file and discarded when loaded into the JVM virtual machine
Retentionpolicy.runtime: Annotations remain during a program run, at which point all annotations defined on a class can be obtained through reflection.

@Target: Used to indicate that the annotation can be declared before those elements.
Elementtype.type: Note that the note can only be declared before a class.
Elementtype.field: Note that the note can only be declared in front of a field in a class.
Elementtype.method: Indicates that the annotation can only be declared before a method of a class.
Elementtype.parameter: Note that the note can only be declared before a method parameter.
Elementtype.constructor: Note that the annotation can only be declared before the constructor of a class.
Elementtype.local_variable: Note that the note can only be declared before a local variable.
Elementtype.annotation_type: Note that the note can only be declared before an annotation type.
Elementtype.package: Note that the note can only be declared before a package name.

@Constraint to limit the way custom annotations are defined
The class that is written here is the following custom class

The methods inside the interface are those on other annotations, such as @past

Https://www.phpsong.com/3567.html

Spring Boot Custom Validator annotations

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.