gpt4 book ai didi

java - Spring MVC的AddAllAttributes方法

转载 作者:行者123 更新时间:2023-12-02 08:41:06 27 4
gpt4 key购买 nike

我有两个列表

List<User> list_of_users=new ArrayList<User>();
List<String> list_of_attributes=new ArrayList<String>();

当我尝试使用以下代码行时:

model.addAttribute("takeattributes",list_of_users);
model.addAttribute("takeattributes",list_of_attributes);

我意识到它只保留第二个列表(list_of_attributes)并删除第一个列表。我想知道如何在模型中保留这两个列表。这有可能发生吗?我需要的是 AddAllAttributes 方法吗?如果是的话,谁能解释一下 AddAllAttributes 方法是如何工作的。我查看了 spring mvc 文档但我不太明白。

最佳答案

该模型本质上是一个具有唯一键的Map。您确实应该定义两个唯一的键:

model.addAttribute("users", list_of_users);
model.addAttribute("attributes", list_of_attributes);

第一个参数用作标识符,您可以在 GUI 中引用每个相应的列表。

关于java - Spring MVC的AddAllAttributes方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10866433/

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