• ChannelValidator can be replaced with any class name you want.
  • ConstraintValidator is a built-in validator that we will implement to create our custom validator.
  • ChannelConstraint is the name of the constraint class we will create later on. It’s also will be the name of the annotation.
  • ChannelDTO is the class type that we will validate, if you want to validate a text-based field with String type, replace it with String.
  • I need ChannelRepository to call a findById function, if you only need to validate a String or Integer, ignore this.
  • isValid is the function that we override from ConstraintValidator where we need to put our validation logic on. Replace the first parameter with the class type you want to validate, and leave the second parameter as it is.

#custom-validation #java #spring-framework #annotations #spring-mvc

Creating Spring MVC Custom Validation Annotation
1.15 GEEK