gpt4 book ai didi

java - 如何获取购物车中的多个商品

转载 作者:行者123 更新时间:2023-11-30 08:37:03 25 4
gpt4 key购买 nike

目前我正在使用 java 和 spring 创建一个购物车。

@RequestMapping("/cart")
public String get(Model model, @ModelAttribute("item") Item item) {
Item lol = itemService.get(item.getItemId());
model.addAttribute("item", lol);
model.addAttribute("total", calculateTotal(lol));

return "cart";
}

问题是它只允许存储一个项目..有没有办法在 session 中存储?

最佳答案

Problem is that it is only allowing one item to be stored.. is there a way to store on a session?

不需要将它放在 session 中,您可以简单地使用 List<Item>这样:

List<Item> lolz = itemService.get(item.getAllItems());
model.addAttribute("items", lolz);

然后你迭代List<Item><c:forEach>像这样:

<c:forEach items="${items}" var="item">
<c:out value="${item.name}"/></td>
<form:hidden path="itemId" value="${item.itemId}"/>
<button class="reserve-button" type="submit" name="reserve" id="reserve" value="Reserve Item">
Reserve Item
</button>
</c:forEach>

关于java - 如何获取购物车中的多个商品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37478256/

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