静态资源映射
创建Web工程
WebMvcAutoConfiguration
Ctrl+Shift+R
搜索addResourceHandlers
resourceProperties
可以设置和静态资源有关的参数,缓存时间等
点击,进入
staticPathPattern
添加资源映射
点击,进入
getStaticLocations
静态资源,映射路径
点击,进入
加载路径
private static final String[] SERVLET_RESOURCE_LOCATIONS = new String[]{"/"};
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = new String[]{"classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"};
/**
访问当前项目的任何资源
都去静态资源的文件夹找映射
“/”:当前项目的根路径
“classpath:/META‐INF/resources/”,
“classpath:/resources/”,
“classpath:/static/”,
“classpath:/public/”
访问路径
不需要添加,静态资源目录
端口,直接跟要访问的静态资源即可
localhost:8080/abc
表示,去静态资源文件夹里面找abc
welcomePageHandlerMapping
配置欢迎页映射
欢迎页,就是项目的首页
getWelcomePage
加载页面形式
点击,进入
getStaticPathPattern
被哪个路径映射
点击,进入
欢迎页
静态资源文件夹下的,所有index.html页面
被”/**”映射
比如
localhost:8080/
表示,找index页面
FaviconConfiguration
配置喜欢的图标
faviconRequestHandler
所有 **/favicon.ico
getFaviconLocations
映射资源路径
**/favicon.ico
所有的**/favicon.ico
都是在静态资源文件下找