Thymeleaf + CSS + SpringBoot

I have a problem with CSS and Thymeleaf.

In my Spring boot application, I have this structure:

  • src / main / resource / static / css (for css files)
  • src / main / resource / static / templates (for html file)

Now, with my html page called ErrorPage and a css file called Layout.css using Thymeleaf in my head ErrorPage:

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

But that will not work.

What am I doing wrong?

+4
source share
1 answer

Move the folder templatedirectly below resources:

  • src/main/resource/static/css (for CSS files);
  • src/main/resource/templates (for HTML templates).

Then fix the tag linkas follows:

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

Source: https://habr.com/ru/post/1666475/


All Articles