一、定製首頁:
方式一:SpringBoot自動映射
在靜態資源目錄resources、static、public的其中一個目錄中創建index.html文件,springBoot會自動識別,將這個文件作爲首頁訪問
方式二:使用thymeleaf模板引擎
1.導入依賴
<!--Thymeleaf模板引擎依賴-->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
2.resources目錄下的templates目錄中創建index.html(文件名稱不強制,只要與控制層對應就行)
//java項目www.fhadmin.org
@Controller
public class PageController {
@RequestMapping("/")
public String index(Model model){
model.addAttribute("msg","首頁");
return "index"; //thymeleaf引擎幫我們配置好了視圖解析器,實際返回的頁面爲templates目錄下的index.html
}
}
二、定製404頁面:
在導入了Thymeleaf模板引擎依賴的前提下,定製404頁面非常簡單,在templates目錄下創建error目錄,然後error目錄中創建404.html,Thymeleaf會自動將這個頁面定製爲404頁面