一、静态资源的映射规则
1.对哪些目录映射?
classpath:/META-INF/resources/
classpath:/resources/
classpath:/static/
classpath:/public/
/:当前项目的根路径
意思是:我们在上面的五个目录下放静态资源文件(比如:jq.js等),可以直接访问(类似以前web项目的webapp下,放到其他目录无法被访问。
2.为什是这几个目录呢?
2.1看源码就知道
SpringBoot自动配置的WebMvcAutoConfirarution.java类:
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
if (!this.resourceProperties.isAddMappings()) {
logger.debug("Default resource handling disabled");
return;
}
Duration cachePeriod=this.resourceProperties.getCache().getPeriod();
CacheControl cacheControl=this.resourceProperties.getCache()
.getCachecontrol().toHttpCacheControl();
if (!registry.hasMappingForPattern("/webjars/**")) {