五、SpringBoot集成模版引擎

一、什么是模版引擎

就是偽html,格式是html,但是可以像jsp那樣有動態(tài)數(shù)據(jù),也可以說是動態(tài)頁面靜態(tài)化。

二、有什么作用

可以提高搜索引擎的搜索

三、有那些模版引擎

velocity 、Thymeleaf、framemaker
velocity相關(guān)資料

http://velocity.apache.org

Thymeleaf

官方資料:https://www.thymeleaf.org/documentation.html
其它資料1:https://blog.csdn.net/u014042066/article/details/75614906
其它資料2https://www.cnblogs.com/summercanon/p/7910799.html

framemaker

中文教程文檔:https://download.csdn.net/download/ch656409110/4494063

四、使用案例

這里使用:Thymeleaf 作為模版引擎為例:這里只是參考一下。第五步會有完整案例

上代碼:

1、控制層
@Controller
public class ThymeleafTestController {
    private Logger logger = LoggerFactory.getLogger(ThymeleafTestController.class);
    
@RequestMapping(value = "/hello",method = RequestMethod.GET)
    public String hello(Map<String,Object> maps){
        maps.put("name","張三");
        maps.put("sex","男");
        return "index";
    }
}
2、頁面代碼
<!DOCTYPE html>
<html lang="en">
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>首頁</title>
</head>
<body>
<!--/*@thymesVar id="name" type="java.lang.String"*/-->
<p th:text="'Hello!, ' + ${name} + '!'" >3333</p>
<p th:text="${sex}">aaa</p>
</body>
</html>
3、效果
效果

五、完整步驟集成到SpringBoot

點(diǎn)這里完整步驟集成到SpringBoot

看相關(guān)其它文章先到:目錄大崗

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容