![](https://img.haomeiwen.com/i13511312/ae84000f86751fc6.png)
![](https://img.haomeiwen.com/i13511312/820c489c106baa7c.png)
![](https://img.haomeiwen.com/i13511312/abeb3ed048b3c4f0.png)
![](https://img.haomeiwen.com/i13511312/12c2280d2e39fd68.png)
![](https://img.haomeiwen.com/i13511312/2af9655e9ced7576.png)
maven下载地址
![](https://img.haomeiwen.com/i13511312/5fc5d0cd1aed7e6d.png)
-
自动导入maven
image.png
image.png
- 新建一个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/
网友评论