天天看點

spring boot 通路靜态html、js1 具體1.1 參考1.2 建立 static 檔案夾1.3 建立html檔案1.4 通路檔案

1 具體

1.1 參考

詳細的資料參考 https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot,

加載靜态資源,會從以下幾個路徑查找:

/META-INF/resources/

/resources/

/static/

/public/

WebMvcAutoConfiguration 源碼如下:

private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
        "classpath:/META-INF/resources/", "classpath:/resources/",
        "classpath:/static/", "classpath:/public/" };
           

1.2 建立 static 檔案夾

在項目下,建立 static 檔案夾。也可以是這個路徑 src\main\resources\static。

spring boot 通路靜态html、js1 具體1.1 參考1.2 建立 static 檔案夾1.3 建立html檔案1.4 通路檔案

1.3 建立html檔案

建立檔案,路徑為static\1.html 。 編寫内容為 1。

1.4 通路檔案

spring boot 通路靜态html、js1 具體1.1 參考1.2 建立 static 檔案夾1.3 建立html檔案1.4 通路檔案

繼續閱讀