【SpringBoot】8、首页及图标定制【狂神篇】

【SpringBoot】8、首页及图标定制【狂神篇】,第1张

【SpringBoot】8、首页及图标定制【狂神篇】 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中加入



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5707548.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-18
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存