What is the use of Spring custom annotations
This article mainly introduces the use of Spring custom annotations, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
Field annotation
Field annotations are generally used to verify whether fields meet the requirements. Hibernate-validate dependencies provide a lot of verification annotations, such as @ NotNull, @ Range, etc., but these annotations are not suitable for all business scenarios. For example, if we want the passed parameters to be in the specified String collection, then the existing annotations cannot meet the requirements and need to be implemented by ourselves.
Custom annotation
Define a @ Check annotation and declare an annotation through @ interface
@ Target ({ElementType.FIELD}) / / only allowed to be used on fields of a class @ Retention (RetentionPolicy.RUNTIME) / / annotations can be retained during the run of the program, when all annotations defined on a class @ Constraint (validatedBy = ParamConstraintValidated.class) public @ interface Check {/ * * legal parameter values * * / String [] paramValues () can be obtained by reflection. / * * prompt * * / String message () default "parameter is not specified"; Class [] groups () default {}; Class