1. SpringBoot 静态资源映射规则
webjars
:以JAR包的方式引入静态资源;- 所有
/webjars/**
,都去classpath:/META-INF/resources/webjars/
目录下加载资源; /**
访问当前项目的任何资源(即静态资源文件夹)classpath:/META-INF/resources/
classpath:/resources/
,classpath:/static/
,classpath:/public/
,/
:当前项目的根路径
// WebMvcAutoConfiguration.java@Overridepublic void addResourceHandlers(ResourceHandlerRegistry registry) { if (!this.resourceProperties.isAddMappings()) { logger.debug("Default resource handling disabled"); return; } Integer cachePeriod = this.resourceProperties.getCachePeriod(); if (!registry.hasMappingForPattern("/webjars/**")) { customizeResourceHandlerRegistration(registry .addResourceHandler("/webjars/**") .addResourceLocations("classpath:/META-INF/resources/webjars/") .setCachePeriod(cachePeriod)); } String staticPathPattern = this.mvcProperties.getStaticPathPattern(); if (!registry.hasMappingForPattern(staticPathPattern)) { customizeResourceHandlerRegistration( registry.addResourceHandler(staticPathPattern) .addResourceLocations( this.resourceProperties.getStaticLocations()) .setCachePeriod(cachePeriod)); }}
2. Thymeleaf 模板引擎
- SpringBoot 引入 Thymeleaf 模板引擎
// pom.xml
参考资料: