深入淺析springboot中static和templates區(qū)別
靜態(tài)頁面的return默認(rèn)是跳轉(zhuǎn)到/static/目錄下,當(dāng)在pom.xml中引入了thymeleaf組件,動態(tài)跳轉(zhuǎn)會覆蓋默認(rèn)的靜態(tài)跳轉(zhuǎn),默認(rèn)就會跳轉(zhuǎn)到/templates/下,注意看兩者return代碼也有區(qū)別,動態(tài)沒有html后綴。
1.1 在static下新建hello1.html
運(yùn)行程序,瀏覽器輸入http://localhost:8080/hello1.html

so,可以在根目錄下訪問hello1.html,static目錄類似于傳統(tǒng)Java web中的webroot或webcontent
1.2 也可以通過接口跳轉(zhuǎn)1.2.1 添加接口
@RequestMapping('hello1')public String hello1() { return 'hello1.html';}
1.2.2 注釋掉thymeleaf依賴
<dependencies> <!--<dependency>--> <!--<groupId>org.springframework.boot</groupId>--> <!--<artifactId>spring-boot-starter-thymeleaf</artifactId>--> <!--</dependency>-->
1.2.3 瀏覽器輸入http://localhost:8080/hello1

2.template目錄2.1 在template下新建hello2.html運(yùn)行程序,瀏覽器輸入http://localhost:8080/hello2.html

templates下的動態(tài)頁面不能直接訪問
2.2 通過接口訪問2.2.1 添加接口
注意接口中return的頁面不包含.html后綴
@RequestMapping('hello2')public String hello2() { return 'hello2';}
2.2.2 瀏覽器輸入http://localhost:8080/hello2

3.結(jié)束語
靜態(tài)頁面的return默認(rèn)是跳轉(zhuǎn)到/static/目錄下,當(dāng)在pom.xml中引入了thymeleaf組件,動態(tài)跳轉(zhuǎn)會覆蓋默認(rèn)的靜態(tài)跳轉(zhuǎn),默認(rèn)就會跳轉(zhuǎn)到/templates/下,注意看兩者return代碼也有區(qū)別,動態(tài)沒有html后綴。
4.總結(jié):
改bug需要用心,掉頭發(fā)是不可避免滴!!!
到此這篇關(guān)于深入淺析springboot中static和templates區(qū)別的文章就介紹到這了,更多相關(guān)springboot static和templates區(qū)別內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. 編程語言PHP在Web開發(fā)領(lǐng)域的優(yōu)勢在哪?2. 詳解Android studio 動態(tài)fragment的用法3. Spring Boot和Thymeleaf整合結(jié)合JPA實現(xiàn)分頁效果(實例代碼)4. 基于android studio的layout的xml文件的創(chuàng)建方式5. Android如何加載Base64編碼格式圖片6. 什么是python的自省7. 圖文詳解vue中proto文件的函數(shù)調(diào)用8. .Net Core使用Coravel實現(xiàn)任務(wù)調(diào)度的完整步驟9. 在IDEA中實現(xiàn)同時運(yùn)行2個相同的java程序10. 解決Android studio xml界面無法預(yù)覽問題

網(wǎng)公網(wǎng)安備