四川網(wǎng)站開發(fā)哪家好廣告開戶南京seo
目錄
- 1. index首頁(yè)
- 1.1 index首頁(yè)訪問規(guī)則的源碼
- 1.2 index首頁(yè)的訪問
- 2. 自定義Favicon圖標(biāo)
1. index首頁(yè)
1.1 index首頁(yè)訪問規(guī)則的源碼
package org.springframework.boot.autoconfigure.web.servlet;
......省略部分......// SpringBoot給容器中放WebMvcConfigurationSupport組件// 我們?nèi)绻约悍帕薟ebMvcConfigurationSupport組件,SpringBoot的WebMvcAutoConfiguration都會(huì)失效@Configuration(proxyBeanMethods = false)@EnableConfigurationProperties({WebProperties.class})public static class EnableWebMvcConfiguration extends DelegatingWebMvcConfiguration implements ResourceLoaderAware {......省略部分......@Beanpublic WelcomePageHandlerMapping welcomePageHandlerMapping(ApplicationContext applicationContext, FormattingConversionService mvcConversionService, ResourceUrlProvider mvcResourceUrlProvider) {return (WelcomePageHandlerMapping)this.createWelcomePageHandlerMapping(applicationContext, mvcConversionService, mvcResourceUrlProvider, WelcomePageHandlerMapping::new);}......省略部分......}
......省略部分......
WelcomePageHandlerMapping:
- 訪問/**路徑下的所有請(qǐng)求,都在以前四個(gè)靜態(tài)資源路徑下找,歡迎頁(yè)也一樣
- 找index.html:只要靜態(tài)資源的位置有一個(gè)index.html頁(yè)面,項(xiàng)目啟動(dòng)默認(rèn)訪問
1.2 index首頁(yè)的訪問
可以在靜態(tài)資源目錄下放index.html文件,就能訪問index首頁(yè)。如resources\META-INF\resources\index.html的文件內(nèi)容如下:
<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><title>test title</title>
</head>
<body><h1>hello springboot</h1></body>
</html>
然后訪問http://localhost:8080/,效果如下:
注意:配置文件不要配置spring.mvc.static-path-pattern參數(shù),否則不能訪問index首頁(yè)
另一種方法:也可以通過Controller控制器,對(duì)請(qǐng)求進(jìn)行處理,跳轉(zhuǎn)到index首頁(yè)
2. 自定義Favicon圖標(biāo)
將favicon.ico文件放到靜態(tài)資源目錄下,然后訪問任意一個(gè)URL,就會(huì)顯示小圖標(biāo)。如果沒顯示小圖標(biāo),注意清一下瀏覽器緩存
注意:配置文件不要配置spring.mvc.static-path-pattern參數(shù),否則不能看到Favicon圖標(biāo)
例如,訪問http://localhost:8080/,效果如下所示: