我正在使用 Spring 3.1.0.RELEASE。如何在 Spring 中正确格式化错误消息?在我的属性文件中,我有……</p>
Incomplete.headers.fileData=The file is missing the following required header(s): %s
然后在我的验证课上,我有
public void validate(Object target, Errors errors) {
...
final String missingHeadersStr = Joiner.on(",").join(missingHeaders);
errors.rejectValue("fileData", "Incomplete.headers.fileData", new Object[] {missingHeadersStr}, "The file is missing some required headers.");
然而,即使(通过调试)我已经验证了“missingHeadersStr”字段是非空的,我的 JSP 上显示的所有内容都是
The file is missing the following required header(s): %s
在 Spring 中格式化错误消息的正确方法是什么?对于它的价值,我像这样在 JSP 上显示它们
<form:errors path="fileData" cssClass="error" />