1
我见过的问题与建议将绝对路径转换为相对路径的答案,但这对我来说是不可能的,因为我的HTML文件存储在各种目录中并使用一行代表CSS的模板。所以fragments.html
开始是这样的:Thymeleaf:在css文件中的绝对引用
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head th:fragment="common_header(title)">
<link rel="stylesheet" th:href="@{/css/style.css}" />
:
实际的HTML看起来像
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head th:replace="fragments :: common_header('List Items')">
<title>Main</title>
</head>
<body>
<script th:src="@{/js/rss/list.js}"></script>
:
现在/css/style.css
:
.item-subject::before {
content: url("/images/new.png");
margin-right: 5px;
}
随着上下文路径和所有很明显,这不起作用。但我能做什么呢?我的意思是th:href
使得link
指向一个有效的资源,所以现在CSS的内容也应该以某种方式来保存。
很明显,content
-line必须包含魔法,但我该如何做所有这些工作?
哦不,Spring-Boot不使用Thymeleaf 3 ... – sjngm