記錄是為了更好的成長!
SpringBoot里面沒有我們之前常規web開發的WebContent(WebApp),它只有src目錄
在src/main/resources下面有兩個文件夾,static和templates springboot默認 static中放靜態頁面,而templates中放動態頁面。
但是webapp文件夾可以有,需要配置視圖解析器同樣可以訪問。
1、static文件中(static文件默認是放靜態資源的)
//這樣寫不能訪問static中index文件夾下的index.html頁面 @RequestMapping("index") public String hello() { return "/index/index"; }
//這樣寫才能訪問到 @RequestMapping("index") public String hello() { return "/index/index.html"; }
2、templates文件夾(放視圖模板,就是springBoot的動態頁面,需要引入thymeleaf組件)
templates文件夾中的頁面需要引入thymeleaf組件之后經過控制器返回才能訪問到。
3、springBoot項目中Controller層的頁面重定向問題,需要引入thymeleaf組件
@RequestMapping("index")
public String hello() {
return "/index/index.html";
}
//請求test會重定向到index
@RequestMapping("test")
public String test() {
return "redirect:/index";
}
4、templates文件夾中的頁面中引入static文件中的資源
編譯之后static文件夾下的文件和templates文件夾下的文件其實會出現在同一個目錄下,引入樣式或者默認圖片的時候注意
以上內容代表個人觀點,僅供參考,不喜勿噴。。。
