springboot 專案小結thymeleaf layui 使用小結
阿新 • • 發佈:2018-11-06
- 第一是 thymeleaf 的使用
- th:attr 設定屬性值
- https://blog.csdn.net/sun_jy2011/article/details/40215423
- th 標籤的一些使用
- 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"></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"></i>登入頁</a></dd> --> </dl> </li> </ul>
3thymeleaf 的 安裝 很簡單 匯入maven 並且在 application.配置檔案中進行配置
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.cache=false
spring.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