1

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?
}

そして、jspでは:

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

ビジネスエラーを発生させるための同様の一般的な構造はありますか?

4

1 に答える 1

6

提案どおりに分離されたオブジェクトを使用することも、にビジネスエラーを追加することもできますErrors/BindingResult。個人的には、通常、ビジーネスエラーをBindingResult内に配置します。これは、後でJSP/Viewで表示する方が簡単だからです。この目的のための一般的な構造があるかどうかはわかりません。

を使用するr.rejectValue("property", "error.object");と、それで十分です。または、必要に応じて、グローバルエラーを呼び出して登録できますr.reject("error.object");

于 2012-07-30T09:48:20.353 に答える