后台代碼:
//查詢數據
List lists = Service.selectloading(id);
mmap.put("listmap", lists);
頁面代碼:
<ul th:each="c, State : ${listmap}">
<li th:text="${c.id}" ></li>
<li th:text="${c.name}"></li>
</ul>
使用Thymeleaf 心得體會:
假如你是使用了一對多的,在對象里有個list 那么在它的子標簽,你就該這樣寫了(此處為了拓展 我還用了th:if )
<ul th:each="c, State : ${listmap}">
<li th:text="${c.post_name}" ></li>
<!--下面這個就是我說的對象中 還存在list $就該換成* 去展示了 (c,State 這兩個值 都是自己隨意定義的)-->
<li th:each="c, State : *{statulist}">
<!--如果它的值是1 就顯示這個-->
<div class="col-sm-8" th:if="${c.status} eq 1">
<li><input type="radio" checked />已批准</li>
<li><input type="radio" />申請中</li>
</div>
<!-- 如果它的值是0 就顯示這個-->
<div class="col-sm-8" th:if="${c.status} eq 0">
<li><input type="radio" />已批准</li>
<li><input type="radio" checked />申請中</li>
</div>
</li>
</ul>
lists
