我需要将列表中存在的数据从 Spring Controller 发送到 thymeleaf (html),如何发送数据?收到后如何迭代 thymeleaf 中的数据
最佳答案
将列表放入 ModelMap
或 ModelAndView
对象中,然后在 thymeleaf 页面中使用 th:each
遍历它。
从 Java 端:
modelMap.addAttribute("list", myListOfThings);
从 thymeleaf 侧:
<ul>
<li th:each="item : ${list}">
<span th:text="${item}">Default</span>
</li>
</ul>
关于java - 如何将列表从 Controller 发送到thymeleaf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20535600/