目录结构

类路径下 static/home.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<title>home</title>
<link rel="icon" th:href="@{/favicon.ico}" type="image/x-icon"/>
<link rel="bookmark" th:href="@{/favicon.ico}" type="image/x-icon"/>
或者
<link rel="icon" th:href="@{/static/favicon.ico}" type="image/x-icon"/>
<link rel="bookmark" th:href="@{/static/favicon.ico}" type="image/x-icon"/>
</head>
<body>
<p>static home.html页面</p>
</body>
</html>
模板下 templates/index.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<title>index</title>
<link rel="icon" th:href="@{/favicon.ico}" type="image/x-icon"/>
<link rel="bookmark" th:href="@{/favicon.ico}" type="image/x-icon"/>
</head>
<body>
<p>index .html页面</p>
</body>
</html>
本文通过两个示例展示了如何在Thymeleaf模板中正确引用图标文件。一个示例位于类路径下的static目录,另一个则位于templates目录。这两个示例都详细介绍了如何使用Thymeleaf表达式来链接favicon图标。
6312

被折叠的 条评论
为什么被折叠?



