深入淺析springboot中static和templates區(qū)別

靜態(tài)頁面的return默認是跳轉(zhuǎn)到/static/目錄下,當在pom.xml中引入了thymeleaf組件,動態(tài)跳轉(zhuǎn)會覆蓋默認的靜態(tài)跳轉(zhuǎn),默認就會跳轉(zhuǎn)到/templates/下,注意看兩者return代碼也有區(qū)別,動態(tài)沒有html后綴。

創(chuàng)新互聯(lián)公司-成都網(wǎng)站建設公司,專注網(wǎng)站制作、做網(wǎng)站、網(wǎng)站營銷推廣,域名與空間,雅安服務器托管,綿陽服務器托管有關企業(yè)網(wǎng)站制作方案、改版、費用等問題,請聯(lián)系創(chuàng)新互聯(lián)公司

1.1 在static下新建hello1.html

運行程序,瀏覽器輸入http://localhost:8080/hello1.html

深入淺析springboot中static和templates區(qū)別

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

深入淺析springboot中static和templates區(qū)別

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

深入淺析springboot中static和templates區(qū)別

templates下的動態(tài)頁面不能直接訪問

2.2 通過接口訪問
2.2.1 添加接口

注意接口中return的頁面不包含.html后綴

@RequestMapping("hello2")
public String hello2() {
  return "hello2";
}

2.2.2 瀏覽器輸入http://localhost:8080/hello2

深入淺析springboot中static和templates區(qū)別

3.結束語

靜態(tài)頁面的return默認是跳轉(zhuǎn)到/static/目錄下,當在pom.xml中引入了thymeleaf組件,動態(tài)跳轉(zhuǎn)會覆蓋默認的靜態(tài)跳轉(zhuǎn),默認就會跳轉(zhuǎn)到/templates/下,注意看兩者return代碼也有區(qū)別,動態(tài)沒有html后綴。

4.總結:

改bug需要用心,掉頭發(fā)是不可避免滴?。?!

到此這篇關于深入淺析springboot中static和templates區(qū)別的文章就介紹到這了,更多相關springboot static和templates區(qū)別內(nèi)容請搜索創(chuàng)新互聯(lián)以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持創(chuàng)新互聯(lián)!

文章標題:深入淺析springboot中static和templates區(qū)別
瀏覽地址:http://muchs.cn/article34/gpjgse.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)微信公眾號、虛擬主機、手機網(wǎng)站建設營銷型網(wǎng)站建設、用戶體驗

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設