IntelliJ Spring Boot project can't find my CSS files with Thymeleaf

前端 未结 2 617
眼角桃花
眼角桃花 2021-01-22 05:40

I\'m new to Spring Boot and my problem is that I have Spring Boot project and I am intending to view my HTML pages with Thymeleaf but Spring can\'t resolve my JavaScript and CSS

相关标签:
2条回答
  • 2021-01-22 05:46

    You should use relative path to your JavaScript and CSS files:

    <link href="../../static/css/style.css" rel="stylesheet" type="text/css" media="screen"/>
    

    or you can use th:href Thymeleaf's tag as well:

    <link th:href="@{css/style.css}" href="../../static/css/style.css"
          rel="stylesheet" type="text/css" media="screen"/>
    
    0 讨论(0)
  • 2021-01-22 05:49

    I have found that Spring automatically searches for: /resources/.
    So what I did was removed all the pre-directories by using find all.

    So, in my case what used to be for example: /static/css/style.css & /templates/index.html

    became: /css/style.css & /index.html

    Now the question remains how does Spring boot know what folder to look in without you defining it: Spring looks at the extension. When spring boot sees .html, it looks for it in a folder called /templates.

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