Spring MVC Annotations Date Range Validation

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

  • Date should be before or after specified date;
  • The Time difference in comparison with current time (now) is greater/less then some period of time. (As example check whether User is more than 21 years old).
  • The one way to implement this is to put this functionality inside validators. And in every controller write this logic for myself.

    In order to have better re-use it's possible to create custom annotation. Looking into Existing annotations especially:

  • @Past
  • @Future
  • These annotations are not reusable at all. They've designed for single condition and for me it's a question why it's designed in such way.

    I tend to implement these use cases with creation of new custom annotation. Can anybody suggest better approach or provide some argument against Spring custom annotations?

    链接地址: http://www.djcxy.com/p/61096.html

    上一篇: 使用jquery验证检查值的唯一性

    下一篇: Spring MVC注释日期范围验证