resources目录下
建 application.properties文件
内容如下
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.cache=false
spring.thymeleaf.content-type=text/html
spring.thymeleaf.enabled=true
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.mode=HTML5
建templates文件夹
再在templates文件夹下建一个hello.html文件,内容如下
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<p th:text="${hello}"></p>
</body>
</html>
controller
@Controller
public class TestController {
@GetMapping("/hello")
public String thymeleafTest(Model model){
model.addAttribute("hello","hello");
return "hello";
}
}
启动
访问localhost:8080/hello