深入淺析springboot中static和templates區別
靜態頁面的return默認是跳轉到/static/目錄下,當在pom.xml中引入了thymeleaf組件,動態跳轉會覆蓋默認的靜態跳轉,默認就會跳轉到/templates/下,注意看兩者return代碼也有區別,動態沒有html后綴。
1.1 在static下新建hello1.html
運行程序,瀏覽器輸入http://localhost:8080/hello1.html
so,可以在根目錄下訪問hello1.html,static目錄類似于傳統Java web中的webroot或webcontent
1.2 也可以通過接口跳轉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運行程序,瀏覽器輸入http://localhost:8080/hello2.html
templates下的動態頁面不能直接訪問
2.2 通過接口訪問2.2.1 添加接口
注意接口中return的頁面不包含.html后綴
@RequestMapping('hello2')public String hello2() { return 'hello2';}
2.2.2 瀏覽器輸入http://localhost:8080/hello2
3.結束語
靜態頁面的return默認是跳轉到/static/目錄下,當在pom.xml中引入了thymeleaf組件,動態跳轉會覆蓋默認的靜態跳轉,默認就會跳轉到/templates/下,注意看兩者return代碼也有區別,動態沒有html后綴。
4.總結:
改bug需要用心,掉頭發是不可避免滴!!!
到此這篇關于深入淺析springboot中static和templates區別的文章就介紹到這了,更多相關springboot static和templates區別內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章:
1. javascript xml xsl取值及數據修改第1/2頁2. JavaWeb Servlet中url-pattern的使用3. 使用EF Code First搭建簡易ASP.NET MVC網站并允許數據庫遷移4. HTML5 Canvas繪制圖形從入門到精通5. jsp+servlet簡單實現上傳文件功能(保存目錄改進)6. 淺談SpringMVC jsp前臺獲取參數的方式 EL表達式7. asp(vbs)Rs.Open和Conn.Execute的詳解和區別及&H0001的說明8. XML入門的常見問題(一)9. asp批量添加修改刪除操作示例代碼10. ASP中if語句、select 、while循環的使用方法
