在Spring中格式化错误消息的正确方法是什么?
我正在使用Spring3.1.0.RELEASE。如何在Spring中正确设置错误消息的格式?在我的属性文件中,我有在Spring中格式化错误消息的正确方法是什么?,spring,formatting,Spring,Formatting,我正在使用Spring3.1.0.RELEASE。如何在Spring中正确设置错误消息的格式?在我的属性文件中,我有 Incomplete.headers.fileData=The file is missing the following required header(s): %s 在我的验证课上,我有 public void validate(Object target, Errors errors) { ... final String missingHeadersSt
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" />
说:
errorArgs-错误参数,用于通过MessageFormat绑定参数
(可以为空)
(我的重点)
您正在提供一个可用于String.format()
的模式。但不要用那个。模式应该是:
The file is missing the following required header(s): {0}
说:
errorArgs-错误参数,用于通过MessageFormat绑定参数
(可以为空)
(我的重点)
您正在提供一个可用于String.format()
的模式。但不要用那个。模式应该是:
The file is missing the following required header(s): {0}