1.pom.xml引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2.项目目录结构
具体见图
springboot整合thymeleaf-1.png
3.application.yml配置
spring:
thymeleaf:
mode: HTML
4.创建index.html
路径:/resources/templates/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div>
MESSAGE: <span th:text="${message}"></span>
</div>
</body>
</html>
5.创建controller
package com.ybhy.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class IndexController {
@GetMapping("/")
public String index(Model model) {
model.addAttribute("message", "Building...");
return "index";
}
}
网友评论