8000 GitHub - Coder-ACJHP/SpringMVC-Maven-CustomAnnotations: Custom annotation
[go: up one dir, main page]

Skip to content

Coder-ACJHP/SpringMVC-Maven-CustomAnnotations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
B201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Javax.validation (Custom annotations)

In this project we gonna create own validation annotation(s) and for example we will use it in Spring MVC & Maven web application.

Check this two classes :

1 : CourseCode In this class we need to create
@Annotation class and give it some rules like : @Constraint("tell him from which class will gate rules"),
@Target("tell to app where it can use it like {ElementType.METHOD//in method, ElementType.FIELD//in fields}"), @Retention("tell to app what the policy like: RetentionPolicy.RUNTIME")

    // define default course code
public String value() default "CoderACJHP";

// define default error code
public String message() default "must start with CoderACJHP";

// define default grups
public Class<?>[] groups() default {};

// define default peyloads
public Class<? extends Payload>[] payload() default {};

2: CourseCodeConstraintValidator
In this class we need to create validation logic it's very basic, just at first make the 
class implements ConstraintValidator interface and implemet all methods and override them as you want.


That's it enjoy!
Thank you for reading this.

Releases

No releases published

Packages

No packages published

Languages

0