SpringBoot静态资源文件存放位置

系统默认路径

classpath:/META-INF/resources/
classpath:/resources/
classpath:/static/
classpath:/public/

在这里插入图片描述
访问地址分别为:

localhost:8080/1.html
localhost:8080/2.html
localhost:8080/3.html
localhost:8080/4.html

springboot访问静态资源,默认有两个默认目录:

  • 一个是 src/mian/resource目录(上面将的就是这种情况)
  • 一个是 ServletContext 根目录下( src/main/webapp )

一般来说 src/main/java 里面放Java代码,resource 里面放配置文件、xml, webapp里面放页面、js之类的。

一般创建的maven项目里面都没有 webapp 文件夹,在这里我们自己在 src/main 目录下创建一个 webapp项目目录。

新增静态资源路径

# 静态文件请求匹配方式
spring.mvc.static-path-pattern=/**
# 修改默认的静态寻址资源目录 多个使用逗号分隔
spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/os/

参考文章

原文地址:https://www.cnblogs.com/chmod/p/15489906.html