久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

Spring boot項目使用thymeleaf模板過程詳解

瀏覽:5日期:2023-08-24 10:10:32

在spring boot 項目中使用thymeleaf模板,將后臺數(shù)據(jù)傳遞給前臺界面。

1、將后臺數(shù)據(jù)傳遞給前臺有很多種方式,可以將后臺要傳遞的數(shù)據(jù)轉(zhuǎn)換成json格式,去傳遞給前臺,也可以通過model形式去傳遞出去,這篇博客主要是使用thymeleaf模板,將后臺數(shù)據(jù)傳遞給前臺。

2、首先要在spring boot 項目中添加如下依賴:

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency>

3、這里后臺有關(guān)如何查詢數(shù)據(jù),得到數(shù)據(jù)的具體過程就不在多說了,只是寫將數(shù)據(jù)庫中查詢到的數(shù)據(jù)取出來,放到model里面。這里就一個例子吧。

@RequestMapping('/')public String index(Model model){Person single=new Person('aa',11);List<Person> people =new ArrayList<Person>();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.前臺界面的寫法,

<span th:text='${person.name}'></span> <span th:text='${person.age}'></span>

通過這樣的方法就可以取到放入model中的person的name和age了。

(注:前臺界面要添加上這個代碼:<html xmlns:th='http://www.thymeleleaf.org'>)

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 东安县| 石首市| 盈江县| 宝鸡市| 泸西县| 交城县| 额敏县| 文安县| 古浪县| 彭山县| 饶河县| 吉隆县| 亳州市| 六盘水市| 武宁县| 五寨县| 德昌县| 灵璧县| 镇康县| 津南区| 南阳市| 建水县| 泾阳县| 吉隆县| 会东县| 兴山县| 固始县| 余庆县| 龙川县| 吉安市| 曲周县| 澄江县| 清涧县| 许昌市| 兰西县| 奉节县| 砀山县| 景泰县| 许昌县| 隆子县| 汨罗市|