How to send object that is retrived in a get request to a post requet | Spring Boot Thymeleaf

流过昼夜 提交于 2019-11-28 14:37:43

Alright, I finally resolved it using the following in my form:

<table class="table table-bordered table-striped">
        <thead>
          <tr>
            <td>Source</td>
            <td>Destination</td>
            <td>Amount</td>
            <td>Currency</td>
            <td>Action</td>
          </tr>
        </thead>
        <tbody>
          <tr th:if="${offers.empty}">
            <td colspan="5">No Offers</td>
          </tr>
          <tr th:each="offer, stat : ${offers}">
            <td th:text="${offer.route.from}"></td>
            <td th:text="${offer.route.to}"></td>
            <td th:text="${offer.price.amount}"></td>
            <td th:text="${offer.price.currency}"></td>
            <td>
                <form action="#" th:action="@{/user/booking}"
                        th:object="${booking}" method="post" 
                        role="form">
                        <input type="hidden" th:value="${offer.route.from}" name="routeStart" />    
                        <input type="hidden" th:value = "${offer.route.to}" name="routeDestination" />
                        <input type="hidden" th:value = "${offer.price.amount}" name="bookingCharges" />
                        <input type="hidden" th:value = "${offer.price.currency}" name="chargesCurrency" />
                        <button type="submit" class="btn btn-primary btn-block">Book</button>
                </form>
            </td>
          </tr>
        </tbody>

All it took was to remove th:field and add the name attribute.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!