resources目录下
建 application.properties文件
内容如下
spring.thymeleaf.prefix=classpath:/templates/spring.thymeleaf.suffix=.htmlspring.thymeleaf.cache=falsespring.thymeleaf.content-type=text/htmlspring.thymeleaf.enabled=truespring.thymeleaf.encoding=UTF-8spring.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
@Controllerpublic class TestController {@GetMapping("/hello")public String thymeleafTest(Model model){model.addAttribute("hello","hello");return "hello";}}
启动
访问localhost:8080/hello
