2

に問題があります@ModelAttribute

CustEntity「名前」などのオブジェクトがありますBankAccEntity。番号と名前を持つ、呼び出された bankAcc のリストもあります。

GET メソッドで、getBankAcc()cust has arraylist with bankaccounts を使用すると、オブジェクト「顧客」を GET から POST に渡すと、BankAccリストに [] があります;/

私のコードフラグメントは以下の通りです:

    @RequestMapping(value = "/aaa.html", method = RequestMethod.GET)
public String aaaGet(Model m, Principal principal) {

...
    CustEntity cust = custService.getCustByUserName(principal);
    cust.getBankAcc();

    m.addAttribute("customer", cust);

...
}


@RequestMapping(value = "/aaa.html", method = RequestMethod.POST)
public String aaaPost(
        @ModelAttribute("customer") CustomerEntity cust,
        BindingResult results, RedirectAttributes redirectAttributes,
        Model m) {

    cust.getBankAcc();

    ...
}

よろしく、swerzy

4

2 に答える 2

1

aaaPostでは、CustomerEntitycustがフォームのデータにバインドされます。つまり、aaaPostのcustは、aaaGetのモデルに入れたものではありません。

于 2012-10-17T12:57:08.047 に答える
0

私もこの問題に固執し、解決策を得ました:

ページにスプリング フォームを追加します。

<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %> 

そして、次のようなフォームを使用します。

<form:form action="/someUrl" modelAttribute="objectName" method="post">
     <form:input path="fieldName"/>
     <button type="submit">buttonName</button>
</form:form>
于 2015-01-20T22:56:04.347 に答える