springboot默认不支持jsp
所以需要网页模板;推荐模板引擎 thymeleaf
网页 = 模板 + 数据
引入thymeleaf
- 可以直接再创建时,将该选项勾上
或者后期加入该依赖;
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.thymeleaf</groupId> <artifactId>thymeleaf-spring5</artifactId> </dependency> <dependency> <groupId>org.thymeleaf.extras</groupId> <artifactId>thymeleaf-extras-java8time</artifactId> </dependency> </dependencies>
使用thymeleaf
- 上图得知只需将 html,放入类路径的templates中即可;
- https://www.thymeleaf.org/documentation.html 使用文档地址
html文件导入命名空间
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <p th:text="${home.welcome}">Welcome to our grocery store!</p> </body> </html>