Javascript 未在thymeleaf模板中加载静态资源

Javascript 未在thymeleaf模板中加载静态资源,javascript,css,spring,thymeleaf,Javascript,Css,Spring,Thymeleaf,我是spring thymeleaf的新手,我有一个分为页眉、正文和页脚的网页,但当我尝试包含页眉时,css和js不会加载到网页中 我的文件夹结构如下所示: Do not repeat the head element in the fragment. What you are currently doing is trying to append a duplicate head element in body. Include in fragment only the body parts

我是spring thymeleaf的新手,我有一个分为页眉、正文和页脚的网页,但当我尝试包含页眉时,css和js不会加载到网页中

我的文件夹结构如下所示:

Do not repeat the head element in the fragment. What you are currently doing is trying to append a duplicate head element in body. Include in fragment only the body parts of the header as you'd do in a jsp import.

You can change:

<script src="../../js/bootstrap-min.js"></script>

不要在片段中重复head元素。您当前正在尝试在body中附加一个重复的head元素。与jsp导入一样,只在片段中包含标题的主体部分。

您可以更改:

<script th:src="@{/resources/js/bootstrap-min.js"></script>



感谢您的回复,我通过在spring mvc配置中更正资源路径解决了问题,但没有考虑复制头。非常感谢您指出潜在的问题。如果您使用诸如“../../js/bootstrap-min.js”之类的src,请在回答中添加一些解释,说明此回答如何帮助解决当前问题。它只在localhost中的静态html中使用。在服务器中部署时,我们应该根据url获取js和css,如:“”。在更改为“@{/resources/js/bootstrap-min.js”之后,thymeleaf会将url解释为正确的url