springboot 首頁處理
阿新 • • 發佈:2021-08-09
首頁處理
@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) { returnindexHtml; } } 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/看結果!