如何使用 Hibernate Validator 标准化和组织错误消息(在 Spring 框架下运行)

发布于 2024-10-01 08:02:55 字数 214 浏览 6 评论 0原文

我正在学习 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事未完 2024-10-08 08:02:56

您可能需要检查这个<手册中的 /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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文