基于注释的验证框架 [英] annotation-based validation framework

查看:67
本文介绍了基于注释的验证框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个基于注释的验证框架,该框架将允许我验证参数值.类似于以下内容:

I'm looking for an annotation-based validation framework, that would allow me to validate parameter values. Something like the following:

void someMethod(@NotBlank String foo, @NotEmpty Collection bar, @Positive Integer baz, @NotNull Object obj) {

}

每当调用带注释的方法/构造函数时,参数的验证应自动发生,以使没有办法绕过验证.

Validation of the parameters should happen automatically whenever an annotated method/constructor is called, so that there no way to bypass the validation.

如果我可以自定义产生的错误消息,那就太好了.我正在使用Java 1.5.

If I could customise the error messages produced that would be nice. I'm using Java 1.5.

推荐答案

尝试看看 OVal JSR-303 (也称为Bean验证)

Try taking a look at OVal and others implementors of the JSR-303 (aka Bean validation)

这篇关于基于注释的验证框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆