List list = new ArrayList<>();
list.add("三国演义");
list.add("红楼梦");
list.add("西游记");
list.add("水浒传");
list.add("京华烟云");
ModelAndView mav = new ModelAndView();
mav.addObject("list",list);
mav.setViewName("xxxx");
return mav;
前端xxxx页面,引入Thyemeleaf 模版
<p>法1</p>
<table>
<thead>
<tr>
<th><span th:text="${list[1]}"></span></th>
<th><span th:text="${list[2]}"></span></th>
<th><span th:text="${list[3]}"></span></th>
<th><span th:text="${list[4]}"></span></th>
<th><span th:text="${list[0]}"></span></th>
</tr>
</thead>
</table>
<p>获取list下标</p>
<table>
<thead>
<tr th:each="item,itemStat:${list}" >
<th><span th:text="${itemStat.count}"></span></th>
</tr>
</thead>
</table>
//最好 设置List类型 为map,用key 访问.
Themeleaf 循环遍历list
最新推荐文章于 2024-08-07 09:02:31 发布
本文介绍如何使用Thymeleaf模板引擎在前端页面上渲染Java后端传递过来的书籍列表,并展示了两种不同的渲染方式:直接指定列表元素和通过迭代遍历列表。
6185

被折叠的 条评论
为什么被折叠?



