springBoot的模版引擎
生活随笔
收集整理的這篇文章主要介紹了
springBoot的模版引擎
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
模版引擎
常見的模版引擎有JSP、Velocity、Freemarker和Thymeleaf
Thymeleaf模版
- 使用時需要把html頁面放在classpath:/templates/文件夾下,thymeleaf就能自動渲染
- 創(chuàng)建模版文件,并需要導入thymeleaf的名稱空間 <html lang="en" xmlns:th="http://www.thymeleaf.org">
- 使用模版 <!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head><meta charset="UTF-8"><title>[[${title}]]</title> </head> <body> <h1 th:text="${title}"></h1> <div th:text="${info}">這里的文本之后將會被覆蓋</div> </body> </html>
- 在controller里面準備模版需要的數(shù)據(jù) @Controller public class HelloT {@RequestMapping("/ht")public String ht(Model model) {model.addAttribute("title","hello Thymeleaf").addAttribute("info","this is first thymeleaf test");return "t1";} }
語法規(guī)則
th:text --》改變元素里面的文本內容
th:任意的html屬性 --》替換原生的屬性的值;html屬性值只要加上了th:就相當于兼容了Thymeleaf模版
- 參考文檔
- 中文參考
?
?
?
總結
以上是生活随笔為你收集整理的springBoot的模版引擎的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 平安消费金融逾期了怎么办 怎么处理平安消
- 下一篇: 解决使用MinGW编译C++代码报can