第一是 thymeleaf 的使用
th:attr 设置属性值https://blog.csdn.net/sun_jy2011/article/details/40215423th 标签的一些使用https://segmentfault.com/a/1190000009903821

th:if th:text th:value th:selected 等等

<a href="register.html" title="" th:unless="${session.user} ne null" >Register</a> <a href="login.html" th:unless="${session.name} ne null" title="">Sign in</a> <a th:href="@{/logout}" th:if="${session.user}" title="">Log out</a> <span th:if="${session.user}"> <a th:href="@{/{id}/info(id=${session.user.id})}" >Info</a> </span>> <a th:href="@{/admin_login.html}" th:unless="${session.user} ne null" title="">后台</a> <a th:href="@{/admin_index.html}" th:if="${session.user} ne null" title="">后台</a> <a th:href="@{/login}" th:if="${session.user} " title="" th:text="'欢迎'+ ${session.name} + '!'">Log out</a>thymeleaf 下拉回显选中

<option value="其他" th:selected="${CloudDilatationDto.resource == '其他'}">其他</option>


thymelaf 的 循环迭代

<ul class="layui-nav layui-nav-tree" lay-filter="side-main" > <li class="layui-nav-item" th:each="menu: ${list}"> <a href="javascript:;" th:text="${menu.text}"> <i class="layui-icon">&#xe620;</i>基础</a> <dl class="layui-nav-child"> <dd th:each="record:${menu.childmenus}"> <!-- th:href="@{${record.href}}" --> <!-- <span th:text="${record.href}" class="change"></span> --> <a th:href="@{${record.href}}" > <i class="layui-icon" ></i> <span th:text="${record.ctext}"></span> </a> </dd> <!-- <dd><a href="javascript:;" href-url="login.jsp"><i class="layui-icon">&#xe621;</i>登录页</a></dd> --> </dl> </li> </ul>


3thymeleaf 的 安装 很简单 导入maven 并且在 application.配置文件中进行配置

spring.thymeleaf.mode=LEGACYHTML5spring.thymeleaf.cache=falsespring.thymeleaf.prefix=/WEB-INF/spring.thymeleaf.suffix=.html

maven文件

<!-- thymeleaf模板引擎,访问静态资源 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><!-- 引入该包为了让application.properites中的 spring.thymeleaf.mode=LEGACYHTML5 生效,是为了解决 thymeleaf模板引擎过于严格的HTML校验--><dependency><groupId>net.sourceforge.nekohtml</groupId><artifactId>nekohtml</artifactId></dependency>


4总结

thymeleaf 是很不错的模板 和jsp freeemaker 比较相似 但还是有不同 是springboot 推荐的模板标签。

不同之处:
https://blog.csdn.net/qq_33314107/article/details/80834894