11、java SpringBoot Thymeleaf模板引擎
html引入依赖 <html lang="en" xmlns:th="http://www.thymeleaf.org">
controller传递的参数使用 $,配置文件中传递的参数 使用 #
1、添加连接 th:href="@{/user/emps}"
2、元素中添加文本 th:text="#{login.btn}"
th:text="${emp.getId()}"
3、直接添加文本 [[${session.loginUser}]]
4、添加文本时使用 if判断 th:text="${msg}" th:if="${not #strings.isEmpty(msg)}"
th:text="${emp.getGender()==0 ? '女':'男'}"
5、模块复用 th:fragment="topnavbar" 声名可以复用的模块
th:replace="~{/commons::topnavbar}" 使用声名好的模块
6、模块复用传参 th:replace="~{/commons::leftnavbar(active='list.html')}" 使用时向模块传参
th:class="${active=='main.html' ? 'nav-link active' : 'nav-link'}" 模块中使用参数
7、遍历参数生成 html代码
<tr th:each="emp:${emps}">
<td th:text="${emp.getId()}"></td>
<td th:text="${emp.getLassName()}"></td>
<td th:text="${emp.getGender()}"></td>
<td th:text="${emp.getEmail()}"></td>
<td th:text="${emp.getBrith()}"></td>
<td th:text="${emp.getDepartment().getDepartmentName()}"></td>
</tr>
8、日期Date 转换 th:text="${#dates.format(emp.getBrith(),'yyyy-MM-dd HH:mm:ss')}"
9、默认日期格式 yyyy/MM/dd
配置文件中修改 spring.mvc.data-format=yyyy-MM-dd
10、下拉框参数选择 option中 满足 后面的条件 则选择
th:selected="${emp.getDepartment().getId() eq dep.getId()}"
11、选择框 th:checked="${showState==0}" 选框的 value等于${showState}时选中
12、a标签传参 th:href="@{/updatelist.html(employee=${emp})}"