1、首页
1)源码分析
@Configuration
...
public class WebMvcAutoConfiguration {
@Configuration
...
public static class EnableWebMvcConfiguration{
// this.mvcProperties.getStaticPathPattern() 得到静态资源路径
@Bean
public WelcomePageHandlerMapping welcomePageHandlerMapping(..., ResourceUrlProvider mvcResourceUrlProvider) {
WelcomePageHandlerMapping welcomePageHandlerMapping = new WelcomePageHandlerMapping(new TemplateAvailabilityProviders(applicationContext), applicationContext, this.getWelcomePage(), this.mvcProperties.getStaticPathPattern());
welcomePageHandlerMapping.setInterceptors(this.getInterceptors(mvcConversionService, mvcResourceUrlProvider));
welcomePageHandlerMapping.setCorsConfigurations(this.getCorsConfigurations());
return welcomePageHandlerMapping;
}
}
}
final class WelcomePageHandlerMapping {
...
// 静态资源路径下的 index.html文件
WelcomePageHandlerMapping(.., Resource welcomePage, String staticPathPattern) {
if (welcomePage != null && "/**".equals(staticPathPattern)) {
logger.info("Adding welcome page: " + welcomePage);
this.setRootViewName("forward:index.html");
} else if (this.welcomeTemplateExists(templateAvailabilityProviders, applicationContext)) {
logger.info("Adding welcome page template: index");
this.setRootViewName("index");
}
}
}
2)index.html
把
index.html
放在任一静态文件路径下即可
2、图标
在Spring Boot2.2.x中,将默认的favicon.ico移除,同时也不再提供上述application.properties中的属性配置
实现方式
- 把图标放在任一静态资源路径下;图标名字不要用
favicon.ico
,可改为favicon1.ico
- 在html页面的head中加入
<link rel="shortcut icon" href="/favicon1.ico"/>
<link rel="bookmark" href="/favicon1.ico"/>