參考鏈接 :https://www.cnblogs.com/csguo/p/9596973.html
Springboot中直接訪問html時
Springboot中直接訪問html時
application.properties添加如下配置:
# 定位模板的目錄
spring.mvc.view.prefix=classpath:/templates/
# 給返回的頁面添加后綴名
spring.mvc.view.suffix=.html
# 定位模板的目錄
spring.mvc.view.prefix=classpath:/templates/
# 給返回的頁面添加后綴名
spring.mvc.view.suffix=.html
controller返回頁面:
@GetMapping("/index")
public String index(){
return "home"; //當瀏覽器輸入/index時,會返回 /templates/home.html頁面
}
注意:
spring boot默認開啟了靜態文件的配置,任何放在static文件夾下的資源都是靜態文件。引用靜態文件時以/或者前綴不加任何定位符,都會去static文件夾下查找。
Thymeleaf模版默認會使用templatess作為視圖文件下
@GetMapping("/index")
public String index(){
return "home"; //當瀏覽器輸入/index時,會返回 /templates/home.html頁面
}
注意:
spring boot默認開啟了靜態文件的配置,任何放在static文件夾下的資源都是靜態文件。引用靜態文件時以/或者前綴不加任何定位符,都會去static文件夾下查找。
Thymeleaf模版默認會使用templatess作為視圖文件下