<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
@Controller
public class MyController {
@GetMapping("/")
public String index() {
return "index";
}
}
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>My Page</title>
</head>
<body>
<h1>Welcome to my page</h1>
</body>
</html>
<div th:text="${message}">Hello, World!</div>
@Controller
public class MyController {
@GetMapping("/")
public String index(Model model) {
model.addAttribute("message", "Hello, Thymeleaf!");
return "index";
}
}
<div th:if="${user != null}" th:text="${user.username}">John Doe</div>
<div th:unless="${user != null}" th:text="'Guest'">Guest</div>
<ul>
<li th:each="item : ${items}" th:text="${item}">Item</li>
</ul>