Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Spring中格式化错误消息的正确方法是什么?_Spring_Formatting - Fatal编程技术网

在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

我正在使用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 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}