Thymeleaf + CSS + SpringBoot

Luc*_*epe 16 css3 thymeleaf spring-boot

我有CSS和Thymeleaf的问题.

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

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

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

<link href="../css/Layout.css" th:href="@{css/Layout.css}" type="text/css" />
Run Code Online (Sandbox Code Playgroud)

但这不起作用.

我究竟做错了什么?

Dim*_*San 27

template文件夹移到右下方resources:

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

然后link按如下方式更正标记:

<link href="../static/css/Layout.css" th:href="@{/css/Layout.css}" rel="stylesheet" />
Run Code Online (Sandbox Code Playgroud)

  • 对我不起作用,给出错误“除非您实现 org.thymeleaf.context.IWebContext,否则不能是上下文相关的(/)或页面相关的” (6认同)
  • 为什么我们同时需要'href'和'th:href'? (4认同)