Java BindingResult验证错误,那么业务错误呢?

Java BindingResult验证错误,那么业务错误呢?,java,spring,spring-mvc,Java,Spring,Spring Mvc,我理解BindingResult用于验证与表单相关的错误。但是,关于业务错误,例如: public String bulkUpdate(@ModelAttribute form, BindingResult r) { //do validation, extract selected issues to be bulk updated, etc. //any form related, binding errors to be put in r //this part List<Stri

我理解BindingResult用于验证与表单相关的错误。但是,关于业务错误,例如:

public String bulkUpdate(@ModelAttribute form, BindingResult r) {
//do validation, extract selected issues to be bulk updated, etc.
//any form related, binding errors to be put in r

//this part
List<String> results = service.bulkUpdate(issues, newValues);

//where is it appropriate to put the results?
//from experience we just create a request attribute and put it there
request.setAttribute("bulkUpdateErrors", StringUtils.join(results, "<br>"))

//is there an similar generic structure like Errors?
}
公共字符串bulkUpdate(@modeldattribute表单,BindingResult r){
//进行验证,提取要批量更新的选定问题等。
//任何与表单相关的绑定错误都要放在r中
//这部分
列表结果=service.bulkUpdate(问题、新值);
//把结果放在哪里合适?
//根据经验,我们只需创建一个请求属性并将其放在那里
request.setAttribute(“bulkUpdateErrors”,StringUtils.join(results,
”) //是否存在类似于错误的通用结构? }
在jsp中:

<div id='info'> 
    <c:if test="${not empty bulkUpdateErrors}">
        <spring:message code="bulk.update.warning" /> ${bulkUpdateErrors}
    </c:if>
</div>

${bulkUpdateErrors}

是否有类似的通用结构来放置业务错误?

您可以按照建议使用分离对象,或者可以将业务错误添加到
错误/BindingResult
。就我个人而言,我通常将业务错误放在BindingResult中,因为后者更容易在JSP/View中显示。我不知道是否有任何通用结构用于此目的


使用
r.rejectValue(“属性”、“错误对象”),足够了。或者,如果需要,可以通过调用
r.reject(“error.object”)

您可以按照建议使用分离对象,也可以将业务错误添加到
错误/BindingResult
。就我个人而言,我通常将业务错误放在BindingResult中,因为后者更容易在JSP/View中显示。我不知道是否有任何通用结构用于此目的


使用
r.rejectValue(“属性”、“错误对象”),足够了。或者,如果需要,可以通过调用
r.reject(“error.object”)

感谢Jelies格式化jsp/html代码段感谢Jelies格式化jsp/html代码段