<div class="item active" th:if="${iterStat.index==0}" th:each="img,iterStat:${pics}">
<img th:src="${img.path}" style="width: 303px;height: 171px;"/>
</div>
解說:
對arrayList對象pics遍歷,使用img作為接受參數接收,使用iterStat作為pics下標值,通過iterStat.index得到當前所處下標值;
通過th:src="${img.path}"得到對象中圖片路徑設置圖片顯示圖
<tr th:each="prod,iterStat : ${prods}" th:class="${iterStat.odd}? 'odd'"> <td th:text="${prod.name}">Onions</td> <td th:text="${prod.price}">2.41</td> <td th:text="${prod.inStock}? #{true} : #{false}">yes</td> </tr>
解說:
判斷下標是否未奇數,設置tr樣式