I have a product object list and I want to iterate it in HTML page based on some conditions. I want to iterate this only for the products, which product type is 'BAR'. I have done this as follows.
<th:block th:if="${#strings.isEmpty(foo.destination)}" >
<div th:each ="product, prodStat:${foo.productList}" th:if="${product.type eq 'BAR'}" th:with="bar=${product}">
<div th:text="${bar.cityName}">London</div>
</div>
</th:block>
But now I want product list to iterate only for the first 5 'BAR' products only. How can I achieve this?