重复html片段利用
th:replace
th:insert
th:include
<!--写在要利用标签里-->
<div th:replace="~{commons/bar::fragmentTop}"></div>
<!--引入fragmentTop-->
<div th:replace="~{commons/bar::fragmentTop}"></div>
动态改样式(选项卡亮暗…)
<!--从引用源片段 可赋值activeUrl-->
<div th:replace="commons/bar::#sidebar(activeUrl='dashboard')"></div> <!--sidebar为id故#-->
<!--用时 根据activeUrl改变-->
th:class="${activeUrl=='dashboard'?'nav-link active':'nav-link'}"
表格循环
Collection<Employee> employees = employeeDao.getAll();
model.addAttribute("emps", employees);
//emps是啥 在上
<tr th:each="emp:${emps}">
<td th:text="${emp.id}"></td>
<td th:text="${emp.lastName}"></td>
<td th:text="${emp.email}"></td>
<td th:text="${emp.gender}==1?'男':'女'"></td>
<td th:text="${emp.department}"></td>
<td th:text="${emp.birth}"></td>
</tr>
时间格式
<!--birth一个参,不用${} -->
<td th:text="${#dates.format(birth,'yyyy-MM-dd HH:mm')}"></td>