gpt4 book ai didi

java - thymeleaf 值到 html 选择输入

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

Controller

@GetMapping("/kosik")
public String kosik(Principal principal,Model model){
User user = userServices.findByEmail(principal.getName());
Cart cart = cartServices.findCartByUser(user);
model.addAttribute("produkty",cartItemServices.findAllCartItems(cart));
model.addAttribute("cart",cartServices.findCartByUser(user));
model.addAttribute("user",user);
return "cart";
}

HTML

<ul class="list-group mb-3">
<li th:each="produkt: ${produkty}" class="list-group-item d-flex justify-content-between lh-condensed">
<div>
<h6 th:text="${produkt.product.name}" class="my-0"></h6>
</div>
<span th:text="${produkt.price}" class="d-inline-block"></span><span class="d-inline-block"> €</span>

<form th:action="@{/updateCartItem(name=${produkt.product.name})}" th:object="${cartItem}" method="post">
<select th:field="*{quantity}">
<option th:value="1">1</option>
<option th:value="2">2</option>
<option th:value="3">3</option>
<option th:value="4">4</option>
<option th:value="5">5</option>
</select>
<input type="submit" value="Update" class="btn-sm btn-primary" />
</form>
</li>
<li th:each="kosik: ${cart}" class="list-group-item d-flex justify-content-between">
<span>Total Price</span>
<strong th:text="${kosik.totalPrice}"></strong>
</li>
</ul>

一切都在更新,工作正常,但我无法获取当前的购物车数量来选择 th:field,它仍然是 1,我也尝试过 th:selected,但没有工作..

最佳答案

要修复此问题,您需要删除 th:field 并将其替换为 name 和 id 属性。

<select id="quantity" name="quantity">
<option value="1">1</option>
...
<option value="5">5</option>
<option value="6" selected="selected">6</option>
...
<option value="10">10</option>
</select>

关于java - thymeleaf 值到 html 选择输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60403698/

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