Spring 如何在html中包含保存在静态文件夹中的js文件
我正在使用Spring工具套件构建Spring启动应用程序,并使用thymeleaf作为模板引擎 文件夹结构如下所示:Spring 如何在html中包含保存在静态文件夹中的js文件,spring,spring-boot,spring-mvc,thymeleaf,Spring,Spring Boot,Spring Mvc,Thymeleaf,我正在使用Spring工具套件构建Spring启动应用程序,并使用thymeleaf作为模板引擎 文件夹结构如下所示: src/main/resources/static src/main/resources/templates HTML文件保存在src/main/resources/templates JavaScript文件保存在src/main/resources/static 为了在html中包含javascript文件,我添加了以下行: <script type="text
src/main/resources/static
src/main/resources/templates
HTML文件保存在src/main/resources/templates
JavaScript文件保存在src/main/resources/static
为了在html中包含javascript文件,我添加了以下行:
<script type="text/javascript" th:src="@{../static/js/policyCreations.js}"></script>
但我在chrome控制台中遇到以下错误:
GET net::ERR_中止404
有人能帮我解决这个问题吗根据官方文件: Spring Boot将自动添加位于以下任何目录中的静态web资源:
- /META-INF/资源/
- /资源/
- /静止的/
- /公开的/
请随代码一起写一些解释。在SO-Review中,通常不鼓励只使用代码的答案
<script type="text/javascript" th:src="@{/js/policyCreations.js}"></script>