0

これと同じ種類の動作を行うことは可能ですか:

protected void onBind(HttpServletRequest request, Object command, BindException bindException) throws Exception {
    Invoice invoice = (Invoice) command;

    invoice.getLineItems().removeAll(Collections.singletonList(null));
}

注釈を使用する場合 ? @controller アノテーションを使用しているため、onBind 関数はありません。要素のリストを操作したい(リストからアイテムを削除する)。

4

1 に答える 1

1

新しい方法は、アノテーションでメソッドに@InitBinder注釈を付けることです:

@InitBinder
protected void initBinder(WebDataBinder binder) {
        ...
}

また、メソッドPropertyEditorを呼び出して値を変換するために登録することもできますWebDataBinder.registerCustomEditor。コレクションへの変換にCustomCollectionEditorも便利な場合があります。

于 2012-08-02T18:55:50.960 に答える