springboot 首页处理

首页处理

@Bean
public WelcomePageHandlerMapping welcomePageHandlerMapping(ApplicationContext applicationContext,
                                                           FormattingConversionService mvcConversionService,
                                                           ResourceUrlProvider mvcResourceUrlProvider) {
    WelcomePageHandlerMapping welcomePageHandlerMapping = new WelcomePageHandlerMapping(
        new TemplateAvailabilityProviders(applicationContext), applicationContext, getWelcomePage(), // getWelcomePage 获得欢迎页
        this.mvcProperties.getStaticPathPattern());
    welcomePageHandlerMapping.setInterceptors(getInterceptors(mvcConversionService, mvcResourceUrlProvider));
    return welcomePageHandlerMapping;
}

点进去继续看

        private Resource getWelcomePage() {
            for (String location : this.resourceProperties.getStaticLocations()) {
                Resource indexHtml = getIndexHtml(location);
                if (indexHtml != null) {
                    return indexHtml;
                }
            }
            ServletContext servletContext = getServletContext();
            if (servletContext != null) {
                return getIndexHtml(new ServletContextResource(servletContext, SERVLET_LOCATION));
            }
            return null;
        }

        private Resource getIndexHtml(String location) {
            return getIndexHtml(this.resourceLoader.getResource(location));
        }

静态资源文件夹下的所有 index.html 页面;被 /** 映射。

比如我访问  http://localhost:8080/ ,就会找静态资源文件夹下的 index.html

新建一个 index.html ,在下面的3个目录中任意一个;然后访问测试  http://localhost:8080/  看结果!

springboot 首页处理

 

上一篇:OpenDCIM-19.01操作手册


下一篇:c#使用XSLT将xml文档转换为html文档