【问题标题】:Thymeleaf - passing object to another field without redirectingThymeleaf - 将对象传递到另一个字段而不重定向
【发布时间】:2021-04-19 08:28:48
【问题描述】:

当用户单击this a href 时,我正在尝试从控制器获取此对象列表的此对象 (p):

                 <li th:each="p : ${products}">
                  <figure>
                    <a class="aa-product-img" href="#"><img th:src="${p.picture1min}" style="width: 250px; height: 300px;"></a>
                    <a class="aa-add-card-btn"href="#"><span class="fa fa-shopping-cart"></span>Add To Cart</a>
                     <figcaption>
                      <h4 class="aa-product-title"><a href="#" th:text="${p.nome}">Polo T-Shirt</a></h4>
                      <span class="aa-product-price" th:text="${'R$: ' + #numbers.formatDecimal(p.newPrice, 0, 'POINT', 2, 'COMMA')}"></span><span th:if="${p.isVaryingColor()}" class="aa-product-price"><del th:text="${'R$: ' + #numbers.formatDecimal(p.oldPrice, 0, 'POINT', 2, 'COMMA')}"></del></span>
                    </figcaption>
                  </figure>                     
                  <div class="aa-product-hvr-content">
                    <a href="#" data-toggle="tooltip" data-placement="top" title="Add to Cart"><span class="fa fa-heart-o"></span></a>
                    <a href="#" data-toggle2="tooltip" data-placement="top" title="Espiar" data-toggle="modal" data-target="#quick-view-modal"><span class="fa fa-search"></span></a>                            
                  </div>
                  <!-- product badge -->
                  <span class="aa-badge aa-sale" href="#"  th:if="${p.isVaryingColor()}">Promotion!</span>
                </li>                   

并发送到同一页面上的Quick view product(弹出 div)

 <!-- Modal view content -->
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <div class="aa-product-view-content">
                            <h3>T-Shirt</h3>
                            <div class="aa-price-block">
                              <span class="aa-product-view-price" th:text="${product.price}">$34.99</span>
                              <p class="aa-product-avilability">Avilability: <span>In stock</span></p>
                            </div>
                            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Officiis animi, veritatis quae repudiandae quod nulla porro quidem, itaque quis quaerat!</p>
                            <h4>Size</h4>
                            <div class="aa-prod-view-size">
                              <a href="#">S</a>
                              <a href="#">M</a>
                              <a href="#">L</a>
                              <a href="#">XL</a>
                            </div>
                            <div class="aa-prod-quantity">
                              <input type="text" value="1" th:value="${product.quantity}">
                              <p class="aa-prod-category">
                                Category: <a href="#">Polo T-Shirt</a>
                              </p>
                            </div>
                            <div class="aa-prod-view-bottom">
                              <a href="#" class="aa-add-to-cart-btn"><span class="fa fa-shopping-cart"></span>Add To Cart</a>
                              <a href="#" class="aa-add-to-cart-btn">View Details</a>
                            </div>
                          </div>
                        </div>

显示有关此对象(产品)的信息,但我不想重定向页面,也许有一种方法可以将此对象发送到控制器,搜索数据库并返回产品以进行快速模式查看,而无需重定向页面?

【问题讨论】:

    标签: spring spring-boot spring-mvc thymeleaf


    【解决方案1】:

    我使用 Ajax 解决了这个问题,当用户单击按钮时,ajax 将产品 id 作为参数发送到控制器中的方法并返回到 thymeleaf 页面并 ajax 更新这些字段

    【讨论】:

      猜你喜欢
      • 2020-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-07
      • 2018-10-30
      相关资源
      最近更新 更多