13-SpringBoot进行Web开发

2021-09-15 16:13

阅读:894

首页跳转设置 这我们探究springboot的web项目欢迎页面的设置。 首先我们打开WebMvcAutoConfiguration这个自动配置类 找到一个方法:welcomePageHandlerMapping,源码如下 @Bean public WelcomePageHandlerMapping welcomePageHandlerMapping(ApplicationContext applicationContext, FormattingConversionService mvcConversionService, 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; } 这个方法就是配置加载首页的功能 我们看第三行代码 WelcomePageHandlerMapping welcomePageHandlerMapping = new WelcomePageHandlerMapping(new TemplateAvailabilityProviders(applicationContext), applicationContext, this.getWelcomePage(), this.mvcProperties.getStaticPathPattern()); 其中参数中执行了一个getWelcomPage方法以及获取静态路径的方法 我们先分析getWelcomPage方法,源码如下 private Resource getWelcomePage() { String[] var1 = this.resourceProperties.getStaticLocations(); int var2 = var1.length; for(int var3 = 0; var3


评论


亲,登录后才可以留言!