
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
IndexController.java
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class IndexController {
@RequestMapping("/")
public String index(ModelMap modelMap) {
modelMap.addAttribute("title","hello world") ;
modelMap.addAttribute("content","hello hello") ;
return "index";
}
}
resources/templates/index.html 模板
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8" />
<title th:text="${title}"></title>
</head>
<body>
<h1 th:text="${content}"></h1>
</body>
</html>