springboot中如何使用thymeleaf生成静态页面

2024-10-13 09:22:14

1、首先加入spring-boot-starter-thymeleaf依赖。

springboot中如何使用thymeleaf生成静态页面

2、接下来编写最重要的部分,实现生成静态的代码:(1)构造模板引擎。(2)填充数据。(3)渲染模板生成静态。

springboot中如何使用thymeleaf生成静态页面

3、下面是模板文件位置:

springboot中如何使用thymeleaf生成静态页面

4、模板文件内容很简单,如下:

springboot中如何使用thymeleaf生成静态页面

5、启动run方法,查看日志,如下:可以看到已完成静态文件生成。

springboot中如何使用thymeleaf生成静态页面

6、查看生成静态文件的目录,可以看到已经存在生成的静态文件。

springboot中如何使用thymeleaf生成静态页面

7、打开html文件可以看到,正是我们需要的静态文件。

springboot中如何使用thymeleaf生成静态页面
猜你喜欢