Spring boot 带父对象和子列表的Thymeleaf表单提交
我正在用Spring boot 带父对象和子列表的Thymeleaf表单提交,spring-boot,thymeleaf,spring-webflux,Spring Boot,Thymeleaf,Spring Webflux,我正在用springboot2.3.1和webflux构建一个web应用程序。作为结帐过程的一部分,我想发布一个清单,其中包含订单和行项目列表。理想情况下,我希望在控制器方法中接收Order对象,如下所示: @RequestMapping(value = "/ebooks/order/checkout", method = RequestMethod.POST) public String checkOut(@ModelAttribute Order order, Model
springboot2.3.1
和webflux
构建一个web应用程序。作为结帐过程的一部分,我想发布一个清单,其中包含订单和行项目列表。理想情况下,我希望在控制器方法中接收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
}
公共类秩序{
私有字符串id;
私有字符串状态;
私有字符串customerId;
私人大十进位小计;
private List lineItems=new ArrayList();
//盖特和塞特
}
公共类行项目{
字符串标题;
字符串描述;
字符串作者;
字符串图像;
整数;
大十进制价格;
//盖特和塞特
}
我可以让它工作了。我很快就会在这里发布代码:)我可以让它工作了。我将很快在这里发布代码:)