maven下載地址
-
自動導入maven
- 新建一個loginController,RequestMapping是紅色的鼠標點擊alt+回車
package com.example.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Map;
@Controller
public class loginController {
@RequestMapping("/")
public String loginPage(Map<String, Object> map) {
//通過 map 向前臺頁面傳遞數據
map.put("msg", "hello world");
return "login";
}
}
在resources->templates
文件夾下新建一個login.html
<!DOCTYPE html>
<!--導入thymeleaf的名稱空間-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<!--th:text 爲 Thymeleaf 屬性,用於獲取指定屬性的值-->
<h1 th:text="${msg}"></h1>
</body>
</html>
- 在pow.xml中添加依賴thymeleaf
<!--Thymeleaf 啓動器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
啓動打開http://localhost:8080/