返回介绍

7.5 源文件

发布于 2025-04-22 20:10:00 字数 881 浏览 0 评论 0 收藏

验证器不需要显式注册,但是如果想要从某个属性文件中获取错误消息,则需要通过声明 messageSource bean,告诉 Spring 要去哪里查找这个文件。下面是 app07a 中的 messageSource bean:

< bean id="messageSource" class="org.springframework.context.support.
→ReloadableResourceBundleMessageSource">
  < property name="basename" value="/WEB-INF/resource/messages"/>
< /bean>

这个 bean 实际上是说,错误码和错误消息可以在/WEB-INF/resource 目录下的 messages. properties 文件中找到。

清单 7.4 展示了 messages.properties 文件的内容。

清单 7.4 messages.properties 文件

productname.required.product.name=Please enter a product name
price.required=Please enter a price
price.negative=Price cannot be less than 0 
productiondate.required=Please enter a production date
productiondate.invalid=Please ensure the production date is not later
→than today
typeMismatch.productionDate=Invalid production date 

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。