CSS 文件无法定位 thymeleaf Spring Boot [英] CSS file cannot be located thymeleaf Spring Boot

查看:39
本文介绍了CSS 文件无法定位 thymeleaf Spring Boot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置 Spring 引导服务器,但我无法让 Thymeleaf 链接到 CSS.我知道有很多类似的问题,但没有一个能让我找到答案.

I'm setting up a Spring boot server and I just can't get Thymeleaf to link to the CSS. I know there are a number of similar questions but none of them lead me to an answer.

这是包含在我的home.html"中的链接.

This is the link included in my "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.

bootstrap.min.css links fine but main.css gives me a 404.

项目结构

这是它在网络下的 Web 控制台中向我显示的内容,此 URL 将我带到白标错误

This is what it shows me in the web console under networks, this url takes me to a Whitelabel error

Request URL:http://localhost:8080/styles/main.css

推荐答案

默认情况下应该有一个 static 文件夹并且你的 css 内容应该在那里或者 public 都在里面资源.运行应用程序时查看 springboot 控制台,并查看它从何处提供资源.下面的例子:

By default there should be a static folder and your css content should be there or public all inside resources. Look at the springboot console when you run the app and look where it's serving resources from. Example below:

Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]

根据上述信息相应地设置您的资源位置.

Based on the info above set your resource location accordingly.

这篇关于CSS 文件无法定位 thymeleaf Spring Boot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆