gpt4 book ai didi

spring - 如何在 thymeleaf html 中包含静态文件夹中保存的 js 文件

转载 作者:行者123 更新时间:2023-12-02 20:00:28 25 4
gpt4 key购买 nike

我正在使用Spring Tool Suite构建Spring Boot应用程序并使用thymeleaf作为模板引擎。

文件夹结构如下:

src/main/resources/static  
src/main/resources/templates

HTML 文件保存在 src/main/resources/templatesjavacript文件保存在src/main/resources/static

为了将 javascript 文件包含在我的 html 中,我添加了以下行:

<script type="text/javascript" th:src="@{../static/js/policyCreations.js}"></script>

但我在 chrome 控制台中收到以下错误:

GET http://localhost:8082/static/js/policyCreations.js net::ERR_ABORTED 404

谁能帮我解决这个问题

最佳答案

根据官方文档:

Spring Boot will automatically add static web resources located within any of the following directories:

  • /META-INF/resources/
  • /resources/
  • /static/
  • /public/

因此可以直接引用静态文件夹中的所有文件,而无需指定静态文件夹名称。

喜欢:

<script type="text/javascript" th:src="@{/js/policyCreations.js}"></script>

关于spring - 如何在 thymeleaf html 中包含静态文件夹中保存的 js 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56041061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com