How to add static files using Spring MVC and Thymeleaf

前端 未结 1 1326
遥遥无期
遥遥无期 2021-01-27 12:48

My question is how to add static files like CSS and image files so that I can use them. I am using Spring MVC and Thymeleaf. I looked at various posts on this subject, but they

相关标签:
1条回答
  • 2021-01-27 13:28

    This is how I made it work. Only one line suffice.

    registry.addResourceHandler("/static/**").addResourceLocations("/static/");
    

    And

    <head>
        <link rel="stylesheet" type="text/css" href="/static/css/your.css" th:href="@{/static/css/your.css}"/>
    </head>
    

    If it keeps failing, try to move your "templates" folder into the resources folder as a subfolder.

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