Java FieldError对象中的参数代码是什么?
我的代码中有以下几行。我正在JSP表单中验证验证码。 我不理解Java FieldError对象中的参数代码是什么?,java,spring,spring-mvc,Java,Spring,Spring Mvc,我的代码中有以下几行。我正在JSP表单中验证验证码。 我不理解FieldError对象中传递的所有参数的含义 if (!reCaptchaResponse.isValid()) { FieldError fieldError = new FieldError("CaptchaObj", "captcha", uresponse, false, new String[] { "badCptcha.CaptchaObj.captcha" },
FieldError
对象中传递的所有参数的含义
if (!reCaptchaResponse.isValid()) {
FieldError fieldError = new FieldError("CaptchaObj", "captcha",
uresponse, false, new String[] { "badCptcha.CaptchaObj.captcha" },
null, "Please, Try Again ");
result.addError(fieldError);
}
这里的结果变量的类型为BindingResult
我想知道
FieldError
对象的构造函数中每个参数的确切含义,尤其是String类型的构造函数中的code参数的确切含义。我建议阅读API文档,查找字段错误
它提到了此构造函数的以下参数:
Parameters:
objectName - the name of the affected object
field - the affected field of the object
rejectedValue - the rejected field value
bindingFailure - whether this error represents a binding failure (like a type mismatch); else, it is a validation failure
codes - the codes to be used to resolve this message
arguments - the array of arguments to be used to resolve this message
defaultMessage - the default message to be used to resolve this message
最重要的参数之一是codes参数,它包含将在消息源中搜索的代码。如果找到,将显示与此代码匹配的消息。消息源可以采用参数,因此消息源可以包含如下条目:
typeMismatch.startDate={0} is an invalid date. Use format DD/MM/YYYY.
在这种情况下,代码将是typeMismatch.startDate
,与此代码对应的消息将显示第一个参数,后跟消息。消息的{0}
部分指示它应该显示第一个参数。这些参数由构造函数中的第6个参数提供,在您的示例中,该参数为null。我建议阅读API文档以查找发现的字段错误
它提到了此构造函数的以下参数:
Parameters:
objectName - the name of the affected object
field - the affected field of the object
rejectedValue - the rejected field value
bindingFailure - whether this error represents a binding failure (like a type mismatch); else, it is a validation failure
codes - the codes to be used to resolve this message
arguments - the array of arguments to be used to resolve this message
defaultMessage - the default message to be used to resolve this message
最重要的参数之一是codes参数,它包含将在消息源中搜索的代码。如果找到,将显示与此代码匹配的消息。消息源可以采用参数,因此消息源可以包含如下条目:
typeMismatch.startDate={0} is an invalid date. Use format DD/MM/YYYY.
在这种情况下,代码将是typeMismatch.startDate
,与此代码对应的消息将显示第一个参数,后跟消息。消息的{0}
部分指示它应该显示第一个参数。这些参数由构造函数中的第6个参数提供,在您的示例中为null。@HarshadDeshmukh我已经说到了!我描述了两个更重要的参数,希望这能有所帮助。@HarshadDeshmukh我已经说到了!我描述了两个更重要的参数,希望这有帮助。