Java 使用Thymeleaf将产品添加到购物车

Java 使用Thymeleaf将产品添加到购物车,java,html,spring,thymeleaf,Java,Html,Spring,Thymeleaf,我的数据库中有多个产品记录,其中存储了有关产品的详细信息,如标题、价格、img url等。我在我的网页中显示所有这些产品,如下所示: <div th:each="product : ${products}"> <div class="product-container"> <div class="product"> <p th:text="${pr

我的数据库中有多个产品记录,其中存储了有关产品的详细信息,如标题、价格、img url等。我在我的网页中显示所有这些产品,如下所示:

<div th:each="product : ${products}">
   <div class="product-container">
      <div class="product">

         <p th:text="${product.getTitle()}"></p>             
       
         <strong th:text="${product.getPrice()}"></strong>

         <img th:src="${product.getImageUrl()}">

         <form method="post" th:action="@{/home}">
           <button type="submit" name="action" value="addCartItem">Add To Cart</button>
         </form>

      </div>
   </div>
</div>

添加到购物车
我的问题是,我希望每个“产品部门”都记住它显示的产品

我的意思是,当我单击产品的“添加到购物车”按钮时,我希望在控制器的事件处理程序函数中包含作为参数传递的实际产品

我知道我可以通过
th:object
将对象传递给事件处理程序,并通过
th:field
的输入完成它的字段,但这里我不需要输入,我实际上需要从
th:each=“product:${products}”传递“product”本身

我该怎么做