如何使用 Hibernate Validator 标准化和组织错误消息(在 Spring 框架下运行)
我正在学习 Hibernate Validator。我发现我可以将错误消息文本添加到任何注释中。
但这似乎是处理错误消息的糟糕方法。返回错误消息 ID 并在某些资源文件(如属性文件)中查找消息文本会更清晰。
这样我以后就可以通过交换特定的资源文件来扩展到其他语言;并且错误消息被组织到一个连贯的位置。
使用 Hibernate Validator 的最佳方法是什么?
I'm learning Hibernate Validator. I see that I can add an error message text to any annotation.
But this seems like a bad way to handle error messages. It would be cleaner to return an error message ID and look up the message text in some resource file like a Properties file.
In this way I can later extend to other languages by swapping out the particular resource file; and the error messages are organized into one coherent location.
What's the best approach here with Hibernate Validator?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要检查这个<手册中的 /a> 部分了解 Hibernate Validator 中 i18n 错误描述的方法。
还有另一个 教程 这可能会很方便。
干杯!
You might want to check this section in the manual for an approach of i18n error descriptions in Hibernate Validator.
There is another tutorial which might prove handy.
Cheers!