你好,我试图呈现我的HTML页面thymeleaf但它无法加载.js文件。我使用的是spring-boot,我的文件结构是src/main/resources/templates
,它包含我所有的html文件。我的css文件位于src/main/resources/static/css/
。我的.js文件位于src/main/resources/js/
。Thymeleaf无法加载资源
现在我试图使我的guest.html文件,但它的失败,因为我试图检查对铬元素加载资源,并显示以下错误消息:
http://localhost:8080/js/bootstrap-formhelpers.min.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8080/js/bootstrap.min.js Failed to load resource: the server responded with a status of 404 (Not Found)
下面是我guest.html问题文件无法找到资源:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" th:src="@{https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js}" ></script>
<script src="../js/bootstrap.min.js" th:src="@{js/bootstrap.min.js}"></script>
<script src="../js/bootstrap-formhelpers.min.js" th:src="@{js/bootstrap-formhelpers.min.js}"></script>
在旁注中,当使用'@ {...}'链接url表达式时,您应该始终使用'/'开始您的资源URL。这确保了Thymeleaf将创建一个从上下文路径开始的链接。 –