2021-10-28 16:30

SpringBoot+thymeleaf 显示列表数据

少尉

JavaEE

(1196)

(0)

收藏

一、添加Thymeleaf支持

要使用Thymeleaf,首先在新建项目的时候,勾选Thymeleaf。

image.png

如果一开始忘记勾选了,也可以在pom文件中添加thymeleaf依赖。

image.png

二、添加控制器

新建一个Controller,并添加一个方法。

image.png 

三、显示数据

在templates文件夹下面新建一个list.html文件。

image.png 

在页面里添加thymeleaf的标签支持。

image.png

然后循环显示数据。

image.png

运行项目,访问http://localhost:8080/list

就可以循环把列表中的数据显示出来。

image.png 

0条评论

点击登录参与评论