Java对象验证框架 OVal

fmms 13年前

OVal 是一个可扩展的Java对象数据验证框架,验证的规则可以通过配置文件、Annotation、POJOs 进行设定。可以使用纯 Java 语言、JavaScript 、Groovy 、BeanShell 等进行规则的编写。

示例代码:

private static class TestEntity  {    @Min(1960)    private int year = 1977;      @Range(min=1, max=12)    private int month = 2;      @ValidateWithMethod(methodName = "isValidDay", parameterType = int.class)    private int day = 31;      private boolean isValidDay(int day)    {      GregorianCalendar cal = new GregorianCalendar();      cal.setLenient(false);      cal.set(GregorianCalendar.YEAR, year);       cal.set(GregorianCalendar.MONTH, month - 1);      cal.set(GregorianCalendar.DATE, day);      try {        cal.getTimeInMillis(); // throws IllegalArgumentException      } catch (IllegalArgumentException e) {         return false;      }      return true;    }  }

项目主页:http://www.open-open.com/lib/view/home/1335064055671