According to your comments, you need a list of 4 items, below will be a trick. Let me know if you have a problem.
<ul> <div th:each="excursion,iterStat : ${excursions}" th:if="${iterStat.index}<5"> <li> <a th:href="@{/excursion/{id}(id=${excursion.excursionId})}"><img src="/template/images/garden1.jpg" alt="Image" /></a> <h2 th:text="${excursion.title}"></h2> <p th:text="${#strings.abbreviate(excursion.description,128)}"></p> </li> </div> </ul>
EDIT 1: Further consideration based on the data provided provides another opportunity. Use Map instead of bulk lists in the controller before passing it:
Map<String, List<Excursion>> excursionsList;
Make sure you limit each excursion to 4 (as needed). Then in Thimeleaf iterate over the map.
<div th:each="excursion,rowStat : *{excursionsList}"> <ul> <div th:each="list,iterStat : *{excursion[__${rowStat.index}__].value}"> //your code for each list item information such as excursionId, description etc. </div> </ul> </div>
This should clear the heaps of code and make it as needed.
Aeseir
source share