後端
@GetMapping()
public String c(ModelMap mmap) {
List<Com> slist = companyService.selectCompanyList();
mmap.put("cList", slist);
return "/clist";
}
前端
<select name="coId">
<option value="">所有</option>
<option th:each="c ,cStat: ${cList}" th:text="${c.name}" th:value="${c.id}" th:data-index="${cStat.index}" >
</select>
cStat是狀態變量,有 index,count,size,current,even,odd,first,last等屬性,如果沒有顯示設置狀態變量,thymeleaf會默 認給個“變量名+Stat"的狀態變量。