深入淺析springboot中static和templates區(qū)別
靜態(tài)頁面的return默認(rèn)是跳轉(zhuǎn)到/static/目錄下,當(dāng)在pom.xml中引入了thymeleaf組件,動(dòng)態(tài)跳轉(zhuǎn)會(huì)覆蓋默認(rèn)的靜態(tài)跳轉(zhuǎn),默認(rèn)就會(huì)跳轉(zhuǎn)到/templates/下,注意看兩者return代碼也有區(qū)別,動(dòng)態(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下的動(dòng)態(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組件,動(dòng)態(tài)跳轉(zhuǎn)會(huì)覆蓋默認(rèn)的靜態(tài)跳轉(zhuǎn),默認(rèn)就會(huì)跳轉(zhuǎn)到/templates/下,注意看兩者return代碼也有區(qū)別,動(dòng)態(tài)沒有html后綴。
4.總結(jié):
改bug需要用心,掉頭發(fā)是不可避免滴!!!
到此這篇關(guān)于深入淺析springboot中static和templates區(qū)別的文章就介紹到這了,更多相關(guān)springboot static和templates區(qū)別內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. 利用ajax+php實(shí)現(xiàn)商品價(jià)格計(jì)算2. java 優(yōu)雅關(guān)閉線程池的方案3. JSP頁面實(shí)現(xiàn)驗(yàn)證碼校驗(yàn)功能4. jsp實(shí)現(xiàn)textarea中的文字保存換行空格存到數(shù)據(jù)庫的方法5. jsp EL表達(dá)式詳解6. asp知識(shí)整理筆記4(問答模式)7. ASP實(shí)現(xiàn)加法驗(yàn)證碼8. python selenium 獲取接口數(shù)據(jù)的實(shí)現(xiàn)9. java通過cglib動(dòng)態(tài)生成實(shí)體bean的操作10. Python matplotlib 繪制雙Y軸曲線圖的示例代碼
