簡單介紹:傳遞給後臺一個String類型的list,須要獲取到list的每個元素,而後進行篩選,獲得正確的文本值,看代碼就明白了html
代碼:java
//後臺java代碼
//failList是一個String類型的list,存放的是狀態碼00 01 02 03 04 05 06中的某幾種
map.addAttribute("failMsgList",failMsgList);
return VIEW_PATH + "/failDetail";//跳轉到失敗詳情頁面
//html代碼
<tr th:each="plan : ${planList}" th:id="${plan.planId}"
th:attr="data-plan-status=${plan.planStatus}">
<td th:text="${plan.planName}"></td>
<td th:text="${plan.planCode}"></td>
<div th:switch="${failMsgList.get(__${planStat.index}__)}">
<td th:case="00">後臺系統故障</td>
<td th:case="02">此方案待審覈,不支持下架</td>
<td th:case="01">此方案未上架,不支持下架</td>
<td th:case="04">此方案未上架,不支持下架</td>
<td th:case="03">此方案未上架,不支持下架</td>
<td th:case="06">此方案已經下架</td>
<td th:case="*"></td>
</div>
說明:failList裏的狀態碼的獲取,經過tr循環到第幾行的索引來取
乾貨:spa
<tr th:each="user,userStat:${users}">
userStat是狀態變量,若是沒有顯示設置狀態變量,thymeleaf會默 認給個「變量名+Stat"的狀態變量。code
對arrayList對象users遍歷,使用user做爲接受參數接收,使用userStat做爲users下標值,經過userStat.index獲得當前所處下標值;htm
狀態變量有如下幾個屬性:對象