日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Thymeleaf抽取公共页面片段

發(fā)布時(shí)間:2025/3/20 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Thymeleaf抽取公共页面片段 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

抽取頁(yè)面

項(xiàng)目中,一般把所有的公共頁(yè)面片段都抽取出來
放在一個(gè)獨(dú)立的頁(yè)面中

其他,所有的頁(yè)面根據(jù)需要進(jìn)行引用
參考文檔

th:fragment

抽取公共元素
Name,隨便自定義命名

<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <body> <div th:fragment="copy">&copy; 2011 The Good Thymes Virtual Grocery </div> </body> </html>

th:insert

th:replace

th:include

引入公共元素
使用波浪號(hào)、花括號(hào)方式

<body> ... <div th:insert="~{footer :: copy}"></div> </body>

這兩個(gè)符號(hào)
也可以省略不寫

<body> ... <div th:insert="footer :: copy"></div> </body>

引入兩種方式

選擇器引入
模板名引入

~{templatename::selector}

模板名::選擇器

~{templatename::fragmentname}

模板名::片段名

頁(yè)面頭部
抽取頁(yè)面的頂部欄

<!--topbar--> <nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0" th:fragment="topbar"><a class="navbar-brand col-sm-3 col-md-2 mr-0" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">[[${session.loginUser}]]</a><input class="form-control form-control-dark w-100" type="text" placeholder="Search" aria-label="Search"><ul class="navbar-nav px-3"><li class="nav-item text-nowrap"><a class="nav-link" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#">Sign out</a></li></ul> </nav>

用戶頁(yè)面
引入命名空間

<html lang="en" xmlns:th="http://www.thymeleaf.org">

引用頁(yè)面頂部

<!--引入抽取的topbar--> <!--模板名:會(huì)使用thymeleaf的前后綴配置規(guī)則進(jìn)行解析--> <div th:replace="commons/bar::topbar"></div>

修改完成,刷新頁(yè)面
Ctrl+F9

總結(jié)

以上是生活随笔為你收集整理的Thymeleaf抽取公共页面片段的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。