最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Spring boot项目使用thymeleaf模板过程解析
时间:2022-06-29 00:56:04 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下Spring boot项目使用thymeleaf模板过程解析,文章介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
在spring boot 项目中使用thymeleaf模板,将后台数据传递给前台界面。
1、将后台数据传递给前台有很多种方式,可以将后台要传递的数据转换成json格式,去传递给前台,也可以通过model形式去传递出去,这篇博客主要是使用thymeleaf模板,将后台数据传递给前台。
2、首先要在spring boot 项目中添加如下依赖:
3、这里后台有关如何查询数据,得到数据的具体过程就不在多说了,只是写将数据库中查询到的数据取出来,放到model里面。这里就一个例子吧。
@RequestMapping("/")
public String index(Model model){
Person single=new Person("aa",11);
List people =new ArrayList();
Person p1=new Person("xx",22);
Person p2=new Person("dd",33);
Person p3=new Person("zz",44);
people.add(p1);
people.add(p2);
people.add(p3);
model.addAttribute("singlePerson",single);
model.addAttribute("people",people);
return "index";
}
4.前台界面的写法,
通过这样的方法就可以取到放入model中的person的name和age了。
(注:前台界面要添加上这个代码:
)相关文章
- 卡厄思梦境养成材料怎么获取 养成材料获取途径 10-30
- 卡厄思梦境伙伴怎么获取 伙伴获取攻略 10-30
- 二重螺旋武器图纸怎么获得-武器图纸高效获取攻略 10-30
- 卡厄思梦境救援是什么 救援机制介绍 10-30
- 卡厄思梦境哪些角色比较强 角色节奏榜一览 10-30
- 崩坏因缘精灵墨角兽有什么技能 墨角兽强度解析 10-30