For each dish I have an input to specify the quantity of dishes, but how can I convert it DTO's DishQuantityMap? Where firstInteger - dishId, second - quantity of dishes ordered.
<form action="#" th:action="@{/greeting}" th:object="${Order}" method="post">
<span th:each="dish : ${dishList}">
<input id="number" type="number" value="42">
</span>
</form>
I know I am missing th:field in my code, that is because I don't know how to implement it properly.
public class Order {
private String userName;
Map<Integer, Integer> DishQuantityMap;
}
CodePudding user response:
I don't know what dishList is, but if it has an id field then the code for you form would look something like:
<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>
