Thymeleaf + CSS+SpringBoot

前端 未结 3 1336
别跟我提以往
别跟我提以往 2020-12-03 07:06

I have a problem with CSS and Thymeleaf.

In my Spring boot app, I have this structure:

  • src/main/resource/static/css (for css files)
  • src/main/r
相关标签:
3条回答
  • 2020-12-03 07:29

    Move your template folder right under resources:

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

    Then correct the link tag as follows:

    <link href="../static/css/Layout.css" th:href="@{/css/Layout.css}" rel="stylesheet" />
    
    0 讨论(0)
  • 2020-12-03 07:34

    The main culprit of this behaviour is a custom security configuration which is very likely you are doing in your WebSecurityConfigurerAdapter subclass. If you use SpringBoot 2+ version you should add the following line in your WebSecurityConfigurerAdapter configuration

    .requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()

    0 讨论(0)
  • 2020-12-03 07:52

    Move your template folder right under resources:

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

    Then correct the link tag as follows (relative or absolute):

    <link href="../css/firstcss.css" rel="stylesheet">
    <link href="/css/secondcss.css" rel="stylesheet">
    

    The old solution with static in front doesn't work for me.

    0 讨论(0)
提交回复
热议问题