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; } }