1.pom.xml文件依赖添加
<!-- thymeleaf依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2.在resource目录下面新建templates,并且创建index.html
注意:必须要在html中引入th的标签,不然使用th标签会报错的<html xmlns:th="http://www.thymeleaf.org">
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Thymeleaf入门</title>
</head>
<body>
<span th:text="Hello"></span>
<hr/>
<!-- 获取后台传过来的数据-->
<span th:text="${msg} "></span>
<hr/>
<!--给input框赋值 -->
<input type="text" name="username" th:value="${msg}"/>
<hr/>
</body>
</html>
3.编写java代码
@RequestMapping("/show")
public String show(Model model){
model.addAttribute("msg", "Thymeleaf 第一个案例");
model.addAttribute("key", new Date());
return "index";
}
4.启动项目,访问接口