- 内容提要
- 作者简介
- 译者简介
- 前言
- HTTP
- Servlet 和 JSP
- 下载 Spring 或使用 STS 与 Maven/Gradle
- 手动下载 Spring
- 使用 STS 和 Maven/Gradle
- 下载 Spring 源码
- 本书内容简介
- 下载示例应用
- 第 1 章Spring 框架
- 第 2 章模型 2 和 MVC 模式
- 第 3 章Spring MVC 介绍
- 第 4 章基于注解的控制器
- 第 5 章数据绑定和表单标签库
- 第 6 章转换器和格式化
- 第 7 章验证器
- 第 8 章表达式语言
- 第 9 章JSTL
- 第 10 章国际化
- 第 11 章上传文件
- 第 12 章下载文件
- 第 13 章应用测试
- 附录 A Tomcat
- 附录 B Spring Tool Suite 和 Maven
- 附录 C Servlet
- 附录 D JavaServer Pages
- 附录 E 部署描述符
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
7.5 源文件
验证器不需要显式注册,但是如果想要从某个属性文件中获取错误消息,则需要通过声明 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 绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论