SpringBoot静态资源存放和访问

SpringBoot静态资源存放和访问

一,SpringBoot静态资源存放

以下文件夹通常称为静态文件夹

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

二,SpringBoot静态资源访问

1,访问存放在静态文件夹中的资源

在路径中不需要带上静态资源文件夹名
SpringBoot静态资源存放和访问

http://localhost:8080/jquery-3.2.1.slim.min.js

2,访问欢迎页

默认访问的是存放在静态文件夹中的index.html文件
SpringBoot静态资源存放和访问

http://localhost:8080/
http://localhost:8080/index.html


http://localhost:8080/访问不成功
失败原因1:方法的请求路径与欢迎页访问路径一致
SpringBoot静态资源存放和访问
SpringBoot静态资源存放和访问
失败原因2:在静态文件夹中又创建文件夹,并将欢迎页放入
SpringBoot静态资源存放和访问
因为默认访问只能在静态文件夹下找index.html,可以看作排除文件夹,只查找文件

3,访问favicon.ico

1)通常favicon.ico,SpringBoot会自动进行查找;
2)查找范围在整个项目的所有静态文件夹内,无论是任何层级关系;

即不会像欢迎页只查找子文件,只要在静态文件夹内,就能被找到;
SpringBoot静态资源存放和访问