Spring MVC Annotations Date Range Validation

What is the best way to implement date range validation for the following use case:

  • The date must be before or after the specified date;
  • The difference in time compared to the current time (now) is more / less than a certain period of time. (As an example, check if the user is over 21 years old).

The only way to implement this is to include this function in validators. And in each controller write this logic for yourself.

To improve reuse, you can create a custom annotation . Take particular note of existing notes:

These annotations cannot be reused. They are intended for one condition, and for me it is a question why it was designed in this way.

I try to implement these use cases with creating a new custom annotation. Can anyone suggest a better approach or provide any argument against Spring's custom annotations?

+4
source share

Source: https://habr.com/ru/post/1545114/


All Articles