1.新建springBoot專案
在前面有兩種方式
2.加入thymeleaf模板引擎
SpringBoot推薦使用thymeleaf模板引擎
語法簡單,功能更強大
要想引入thymeleaf,只需要在pom,xml檔案中加入如下依賴就可以了

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
3.在controller中定義跳轉的頁面
會自動去templates檔案夾下去找index.html

4.運行,然后訪問專案
輸入http://localhost:8080/testThymeleaf即可訪問index.html

5.在html頁面中加入thymeleaf模板標簽所需的命名空間

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>測驗thymeleaf模板</title>
</head>
<body>
歡迎來到測驗thymeleaf界面
</body>
</html>
6.將controller資料通過thymeleaf標簽傳到前端界面
把資料放在controller的map中
前端通過標簽取出資料

顯示效果

6.thymeleaf標簽語法
官方檔案
https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.pdf
thymeleaf中文
https://raledong.gitbooks.io/using-thymeleaf/content/Chapter1/section1.1.html
常用標簽介紹



轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/168005.html
標籤:其他
上一篇:支付寶回應手機黑產;微軟將允許員工永久在家辦公;Flutter 1.22 正式發布|極客頭條
下一篇:超過1000多程式員面試經歷,收集了阿里巴巴面試3年總結的108道Java面試題:MySQL+redis+計算機網路+作業系統+Java編程+架構設計
