Search code examples
javahtmlspringthymeleaf

How do I use Thymeleaf th:each to print a list objects in divs, not <td>


I have a list of objects that I pass to a frontend JSP page. I need to display each value in its own div.

For example:

<div class="objects">
    <div class="object"></div>
    <div class="object"></div>
    <div class="object"></div>
    <div class="object"></div>
    ...
</div>

Is there any way to do it this way as opposed to putting it in a table and doing <td>?


Solution

  • The list of Posts data can be printed as below in div

    <div th:each="tempPost:${posts}">
         <div th:text="${tempPost.getContent()}"></div>
         <div th:text="${tempPost.getAuthor()}"></div>
         <div th:text="${tempPost.getCreatedAt()}"></div>
    </div>