1. 程式人生 > 程式設計 >Spring Boot自定義favicon實現方法例項解析

Spring Boot自定義favicon實現方法例項解析

自定義歡迎頁

Spring Boot 專案在啟動後,首先會去靜態資源路徑下查詢index.html作為首頁檔案,若查詢不到,則會去查詢動態的index檔案作為首頁檔案。例如,如果想使用靜態的index.html作為首頁,那麼只需在resources/static 目錄下建立index.html 檔案即可。若想使用動態頁面作為專案首頁,則需在resources/templates 目錄下建立index.html (使用Thyme leaf 模板)或者index.ft! (使用FreeMarker 模板),然後在Controller 中返回邏輯檢視名,程式碼如下:

@RequestMapping("/index")
public String hello(){
   return "index";
}

啟動專案,輸入"http://localhost:8080/"就可以看到專案首頁的內容

自定義favicon

favicon.ico 是瀏覽器選項卡左上角的圖示,可以放在靜態資源路徑下或者類路徑下,靜態資源路徑下的favicon.ico 優先順序高於類路徑下的favicon.ico 。

可以使用線上轉換網站https://jinaconvert.com/cn/convert-to-ico.php 將一張普通圖片轉為.ico 圖片,轉換成功後,將檔案重新命名為favicon.ico , 然後複製到resources/static 目錄下.

Spring Boot自定義favicon實現方法例項解析

最後啟動專案,就可以在瀏覽器選項卡中看到效果了.

Spring Boot自定義favicon實現方法例項解析

去除自動化配置

第一種:

@SpringBootApplication(exclude=WebMvcAutoConfiguration.class)

第二種:

在application.properties中配置:

spring-autoconfigure.exclude=要除去的類名

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。