Отправка формы Thymeleaf с родительским объектом и дочерним списком - PullRequest
1 голос
/ 10 июля 2020

Я создаю веб-приложение с spring boot 2.3.1 с webflux. Как часть процесса оформления заказа, я хотел бы опубликовать, из которого будет иметь заказ и список LineItems. Idelaly, я хотел бы получить объект Order в методе контроллера следующим образом:

@RequestMapping(value = "/ebooks/order/checkout", method = RequestMethod.POST)
public String checkOut(@ModelAttribute Order order, Model model) 

Как я понимаю, список LineItems не заполняется. Как это сделать?

<form action="#" id="checkoutForm" method="post" th:action="@{/order/checkout}">
<input type="hidden" th:value="${cart.subTotal}"  id="subTotal" name="subTotal"/>

<th:block th:each="item : ${cart.items}">
<input type="hidden" th:value="${item.description}"  id="description" name="description"/>
<input type="hidden" th:value="${item.author}"  id="author" name="author"/>
<input type="hidden" th:value="${item.image}"  id="image" name="image"/>
<input type="hidden" th:value="${item.quantity}"  id="quantity" name="quantity"/>
<input type="hidden" th:value="${item.price}"  id="price" name="price"/>
</th:block>

<button type="submit" class="btn btn-primary btn-block waves-effect waves-light">Proceed to
checkout
</button>
</form>

классы:

public class Order {
    private String id;
    private String status;
    private String customerId;
    private BigDecimal subTotal;
    private List<LineItem> lineItems = new ArrayList<>();

    //gettert and setters
}

public class LineItem {
    String title;
    String description;
    String author;
    String image;
    int quantity;
    BigDecimal price;

    //gettert and setters
}
    
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...