springboot-静态资源目录的配置 并且默认 打开indexhtml 文件
在Spring Boot中,可以通过在application.properties文件中配置静态资源目录和默认打开的文件。
- 静态资源目录配置
可以通过设置spring.resources.static-locations属性来配置静态资源目录,多个目录可以用逗号分隔。例如:
spring.resources.static-locations=classpath:/static/,classpath:/public/
上述配置表示将静态资源放在classpath下的static和public目录中。
- 默认打开的文件配置
可以通过设置spring.mvc.static-path-pattern属性来配置默认打开的文件。例如:
spring.mvc.static-path-pattern=/index.html
上述配置表示默认打开的文件是index.html。如果请求的路径是/,则会自动访问index.html文件。
注意:静态资源的访问路径是相对于classpath的,而不是相对于项目根目录的。因此,如果静态资源放在src/main/resources/static目录下,则访问路径应该是/xxx.xxx(xxx.xxx是静态资源文件名)
原文地址: https://www.cveoy.top/t/topic/hfOZ 著作权归作者所有。请勿转载和采集!