Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/330.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.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
Java FieldError对象中的参数代码是什么?_Java_Spring_Spring Mvc - Fatal编程技术网

Java FieldError对象中的参数代码是什么?

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" },

我的代码中有以下几行。我正在JSP表单中验证验证码。 我不理解
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我已经说到了!我描述了两个更重要的参数,希望这有帮助。