2

i have problem with @ModelAttribute,

CustEntity have objects like "name" etc. also have list of BankAccEntity called bankAcc which has number and name.

in GET method when i use getBankAcc() my cust has arraylist with bankaccounts, but when i pass object "customer" from GET to POST, he has [] in BankAcc list;/

my code fragment is below:

    @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();

    ...
}

regards, swierzy

4

2 回答 2

1

在 aaaPost 中,CustomerEntity cust 将与表单中的数据绑定。也就是说,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 回答