gpt4 book ai didi

java - 使用 model 属性传递的 Spring MVC 对象为空

转载 作者:太空宇宙 更新时间:2023-11-04 08:21:20 24 4
gpt4 key购买 nike

我对@ModelAttribute有问题,

CustEntity 具有“名称”等对象,还有名为bankAcc 的BankAccEntity 列表,其中包含编号和名称。

在 GET 方法中,当我使用 getBankAcc() 时,我的客户拥有包含银行帐户的数组列表,但是当我将对象“customer”从 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();

...
}

问候,瑞士人

最佳答案

在 aaaPost 中,CustomerEntity cust 将与您表单中的数据绑定(bind)。也就是说,aaaPost 中的 cust 不是您放入 aaaGet 模型中的那个。

关于java - 使用 model 属性传递的 Spring MVC 对象为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9489586/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com