【发布时间】:2018-03-01 06:37:29
【问题描述】:
我正在设置一个 Spring 引导服务器,但我无法让 Thymeleaf 链接到 CSS。我知道有很多类似的问题,但没有一个能引导我找到答案。
这是我的“home.html”中包含的链接。
<link rel="stylesheet" type="text/css"
href="webjars/bootstrap/3.3.7/css/bootstrap.min.css" />
<link rel="stylesheet" th:href="@{/styles/main.css}"
href="../styles/main.css" />
bootstrap.min.css 链接正常,但 main.css 给我一个 404。
这是它在网络下的 Web 控制台中向我显示的内容,此 url 将我带到 Whitelabel 错误
Request URL:http://localhost:8080/styles/main.css
【问题讨论】:
-
页面的url是什么?是'/'还是下面的东西?
-
Yannic 是什么意思?我只是在 localhost 端口 8080 上运行它。
-
导航到 home.html 时浏览器中的 url。它只是 $host.$tld/ 还是在 '/' 之后有什么东西 例如,如果它的 localhost:8080/home 那么你会在 localhost:8080/home/styles/main.css 中查找 css 它在哪里' t
-
我用来访问此页面的 URL 是 localhost:8080,抱歉,如果我们不是在谈论同一件事。 imgur.com/a/KyilF
-
hm 那么 ref 看起来是正确的。只是为了确定(因为我注意到你刚刚添加了这个 main.css)。您是否重新启动了 Spring Boot 应用程序?你试过正常的href吗? thref 应该不是必需的,因为您没有基于属性构建 url
标签: html css spring-boot thymeleaf