對于每道菜,我都有一個輸入來指定菜的數量,但是如何將其轉換為 DTO 的 DishQuantityMap?其中 firstInteger - discId,second - 訂購的菜肴數量。
<form action="#" th:action="@{/greeting}" th:object="${Order}" method="post">
<span th:each="dish : ${dishList}">
<input id="number" type="number" value="42">
</span>
</form>
我知道我的代碼中缺少 th:field,那是因為我不知道如何正確實作它。
public class Order {
private String userName;
Map<Integer, Integer> DishQuantityMap;
}
uj5u.com熱心網友回復:
我不知道是什么dishList,但如果它有一個 id 欄位,那么你表單的代碼將如下所示:
<form action="#" th:action="@{/greeting}" th:object="${Order}" method="post">
<span th:each="dish : ${dishList}">
<input th:field="*{dishQuantityMap[__${dish.id}__]}" type="number" />
</span>
</form>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/419242.html
標籤:
