Thymeleaf + CSS+SpringBoot [英] Thymeleaf + CSS+SpringBoot

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

问题描述

我在使用 CSS 和 Thymeleaf 时遇到问题.

I have a problem with CSS and Thymeleaf.

在我的 Spring Boot 应用程序中,我有这样的结构:

In my Spring boot app, I have this structure:

  • src/main/resource/static/css(用于 css 文件)
  • src/main/resource/static/templates(用于 html 文件)

现在,使用名为 ErrorPage 的 html 页面和名为 Layout.css 的 css 文件,在 ErrorPage 的头部使用 Thymeleaf:

Now, with my html page named ErrorPage and css file named Layout.css, using Thymeleaf I have, in the head of ErrorPage:

<link href="../css/Layout.css" th:href="@{css/Layout.css}" type="text/css" />

但这不起作用.

我做错了什么?

推荐答案

将您的 template 文件夹移动到 resources 下:

Move your template folder right under resources:

  • src/main/resource/static/css(用于 CSS 文件);
  • src/main/resource/templates(用于 HTML 模板).
  • src/main/resource/static/css (for CSS files);
  • src/main/resource/templates (for HTML templates).

然后更正link标签如下:

<link href="../static/css/Layout.css" th:href="@{/css/Layout.css}" rel="stylesheet" />

这篇关于Thymeleaf + CSS+SpringBoot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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