arjun d n
arjun d n

Reputation: 35

how to send list from controller to thymeleaf

I need to send the data which is present in a list from my spring controller to thymeleaf (html) how can I send the data? after receiving how can I iterate the data in thymeleaf

Upvotes: 2

Views: 1388

Answers (1)

Alex
Alex

Reputation: 25613

Put your list inside your ModelMap or ModelAndView object then traverse it using th:each within your thymeleaf page.

From Java side:

modelMap.addAttribute("list", myListOfThings);

From Thymeleaf side:

<ul>
    <li th:each="item : ${list}">
        <span th:text="${item}">Default</span>
    </li>
</ul>

Upvotes: 2

Related Questions