要在Spring Boot项目中配置静态资源路径,您可以将以下设置添加到您的application.properties文件中:
spring.resources.static-locations=classpath:/static/
在这个例子中,我们将静态资源目录设置为classpath下的静态目录。您也可以设置多个目录,如:
spring.resources.static-locations=classpath:/static/,file:/opt/data/
这将同时搜索应用程序的classpath下的静态资源目录以及/opt/data/目录下的静态资源目录。
注意:如果您使用的是Thymeleaf模板,您可以使用如下表达式来引用静态资源:
<link th:href="@{/css/style.css}" rel="stylesheet" />
通过这个表达式,Thymeleaf会自动将"/css/style.css"解析为静态资源目录中的文件路径。