Combining conditions and iterations in thymeleaf

前端 未结 1 1243
滥情空心
滥情空心 2020-12-12 04:31

I want to generate a list o products using thymeleaf and bootstrap so that I have three products on a row.

If it weren\'t for the rows, I would have done something l

相关标签:
1条回答
  • 2020-12-12 05:10

    I would include Apache Commons Collections 4.1 and use ListUtils to partition the list and iterate like this:

    <th:block th:with="partitions=${T(org.apache.commons.collections4.ListUtils).partition(products, 3)}">
      <div class="row" th:each="partition: ${partitions}">
        <div class="col-sm-4" th:each="product: ${partition}">
          <div class="product">
            <h3 th:text="${product.name}">Product name</h3>
            <img th:src="${product.imagePath}" />
          </div>
        </div>
      </div>
    </th:block>
    
    0 讨论(0)
提交回复
热议问题