package com.shuju.example.Controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping(value = "/web")
public class WebController {
@RequestMapping(value = "index")
public String index(ModelMap map) {
map.put("title", "thymeleaf hello word");
return "index";
}
}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1 th:text="${title}"></h1>
</body>
</html>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
1:引入Thymeleaf
1.1:<html xmlns:th="http://www.thymeleaf.org">
th:
1.2:@{}
2:数据的访问
${}
th:text="${Person.name}"
3:循环
th:each="person:${people}"
4:条件判断;
${not#lists.isEmpty(people)}
5:数据输出
<script th:inline="javascript">
var single=[[${singlePerson}]]
<script>