springBoot加入thymeleaf模板的方式
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.pdfthymeleaf中文https://raledong.gitbooks.io/using-thymeleaf/content/Chapter1/section1.1.html
常用標簽介紹
到此這篇關于springBoot加入thymeleaf模板的方式的文章就介紹到這了,更多相關springBoot thymeleaf模板內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章:
1. IDEA EasyCode 一鍵幫你生成所需代碼2. Ajax引擎 ajax請求步驟詳細代碼3. Java構建JDBC應用程序的實例操作4. Spring應用拋出NoUniqueBeanDefinitionException異常的解決方案5. ThinkPHP5 通過ajax插入圖片并實時顯示(完整代碼)6. javascript設計模式 ? 建造者模式原理與應用實例分析7. 一篇文章帶你了解JavaScript-對象8. Python使用oslo.vmware管理ESXI虛擬機的示例參考9. IntelliJ IDEA設置條件斷點的方法步驟10. Express 框架中使用 EJS 模板引擎并結合 silly-datetime 庫進行日期格式化的實現方法
