gpt4 book ai didi

spring - 什么是 ?

转载 作者:行者123 更新时间:2023-12-03 22:48:16 26 4
gpt4 key购买 nike

什么是<spring:hasBindErrors> ?它有什么用?

我试图谷歌它,但找不到任何有用的内容。

最佳答案

spring:hasBindErrors是一个 Spring 标签,它为您提供与对象绑定(bind)的错误(通常是表单)。在表单对象的验证方法中设置错误。如果绑定(bind)表单对象有错误,那么错误将在 pageScope 中可用。

您可以设置错误如下:

表单对象:

    public class YourForm implements Serializable{
private String name;
private String company;
//mutators
...
}

您正在使用验证方法在验证器中验证此表单:
    public class YourValidator implements Validator{

public boolean supports(Class<?> clazz) {
return clazz.equals(YourForm.class);
}

public void validateYourViewName(YourForm yourForm, Errors errors) {
YourForm yourForm = (YourForm)object;
if (yourForm.getName() == null || yourForm.getName().length() == 0){
errors.rejectValue("name", "name.required", "Name field is missing");
}
}
...
}

在您的 jsp 中,您可以看到以下错误:
    <spring:hasBindErrors name="yourForm">
<c:forEach var="error" items="${errors.allErrors}">
<b><spring:message message="${error}" /></b>
<br/>
</c:forEach>
</spring:hasBindErrors>

标签中的属性: name:绑定(bind)或验证的表单名称。
您还可以从错误中获取更多详细信息:
errors.errorCount:错误数
errors.allErrors:所有错误
errors.globalErrors:为对象注册的错误

您可以从错误对象 here 中找到有关可以检索和查看的内容的更多详细信息。 .

关于spring - 什么是 <spring :hasBindErrors>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23679673/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com