【发布时间】:2019-05-20 01:59:19
【问题描述】:
我在我的 Spring Boot MVC 应用程序中使用 Thymeleaf 模板引擎,但在加载样式时遇到了困难。该链接位于header.html 文件(位于资源/模板/片段下)并在login.html(资源/模板下)中被引用。样式表位于 resources/static/css 目录中。
<head th:fragment="header">
<link rel="stylesheet" href="../../static/css/bootstrap.css" th:href='@{/css/bootstrap.css}' />
</head>
登录.html
<html>
<header th:replace="fragments/header :: header"></header>
<body class="container">
<h1>Login page</h1>
// Code omitted for brevity
</body>
</html>
基于此question 和其他来源,似乎应用程序应该能够使用指定的链接加载样式表。然而,这种情况并非如此。具体来说,如果我查看浏览器的网络选项卡,样式表请求返回 302(不是 404),但未应用样式。此外,如果我在 Firefox 中单击“样式编辑器”选项卡,我会收到一条Stylesheet could not be loaded: http://localhost:8080/css/bootstrap.css 消息。
问题可能是什么? 谢谢。
【问题讨论】:
标签: spring spring-mvc spring-boot thymeleaf