Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 如何在html中包含保存在静态文件夹中的js文件_Spring_Spring Boot_Spring Mvc_Thymeleaf - Fatal编程技术网

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

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

我正在使用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/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>