我正在尝试添加一个片段,其中包含我在每个文件头中所需的内容。但是,当我使用th:insert或th:replace it时,会在插入元素的位置删除已经存在的元素。
fragments/Norm.html
<html>
<head th:fragment="head">
<link rel="stylesheet" th:href="@{/css/main.css}" href="../public/css/main.css" />
</head>
<html>
index.html
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:layout="/index" th:insert="fragments/normal :: head">
<head>
<link rel="stylesheet" th:href="@{/css/index.css}" href="../public/css/index.css" />
</head>
</html>
我预计是这样的:
<html>
<head>
<link rel="stylesheet" th:href="@{/css/main.css}" href="../public/css/main.css" />
<link rel="stylesheet" th:href="@{/css/index.css}" href="../public/css/index.css" />
</head>
</html>
发布于 2019-07-28 21:45:39
只要用th:replace
就行了
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:layout="/index">
<head>
<div th:replace="fragments/normal :: head"></div>
<link rel="stylesheet" th:href="@{/css/index.css}" href="../public/css/index.css" />
</head>
</html>
https://stackoverflow.com/questions/57245057
复制相似问题