導入依賴
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
<html lang="en" xmlns:th="htttp://www.thymeleaf.org">
使用thymeleaf之前記得加上xmlns以及里面的內容 否則所有thymeleaf都不生效
導入本地文件包括jsc、ss、img、都需要在前面加上th:src然后用@{}把整個路勁包起來 link則在href中加th類似
<script type="text/javascript" th:src="@{../static/js/jquery-3.3.1.js}"></script>
<link th:href="@{/myuser/css/bootstrap.min.css}" rel="stylesheet">
文本:th:text轉義字符 即里面內容的標簽內容,th:utext不轉義字符
數組:<h3 th:each ="user:${user}" th:text="{$user}"></h3>
使用<p th:text="${msg}" th:if="${not #string.isEmoty{msg}}"></p> 可以讓標簽在msg為空的時候不顯示這個<p>標簽這個里面的msg是在之前controller里面判斷密碼錯誤之后才賦值的。