1. 程式人生 > 其它 >Springboot(2)---thymeleaf抽取公共部分html

Springboot(2)---thymeleaf抽取公共部分html

技術標籤:Springboot

公共部分抽取為一個html頁面
在其中用如下標籤包裹公共部分
公共頁面index.html

<nav th:fragment="menu" class="navbar navbar-inverse" style="font-size: 18px; background: #5A98D2 ;">
</nav>

在template.html頁面使用如下標籤引入公共部分

<nav th:replace="html/index :: menu"></nav>

目錄關係如下
在這裡插入圖片描述
thymeleaf相關配置:

spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html