1、引入模板thymeleaf
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
增加配置
spring: thymeleaf: prefix: classpath:/templates/
2、增加接口
@RequestMapping("/hello") public String helloHtml(HashMap<String, Object> map) { map.put("hello", "hello world~"); return "/index"; }
3、创建Html页面 index.html 路径为:resources/templates/index.html
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.w3.org/1999/xhtml"> <head> <meta charset="UTF-8" /> <title>Title</title> </head> <body> <p th:text="${hello}"></p> </body> </html>
4、查看效果