如何将列表从控制器发送到百里香叶 [英] how to send list from controller to thymeleaf

查看:23
本文介绍了如何将列表从控制器发送到百里香叶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将列表中存在的数据从我的弹簧控制器发送到百里香 (html) 我该如何发送数据?收到后如何迭代百里香中的数据

I need to send the data which is present in a list from my spring controller to thymeleaf (html) how can I send the data? after receiving how can I iterate the data in thymeleaf

推荐答案

将您的列表放入您的 ModelMapModelAndView 对象中,然后使用 th:each 遍历它 在您的 thymeleaf 页面中.

Put your list inside your ModelMap or ModelAndView object then traverse it using th:each within your thymeleaf page.

从 Java 方面:

modelMap.addAttribute("list", myListOfThings);

来自 Thymeleaf 方面:

From Thymeleaf side:

<ul>
    <li th:each="item : ${list}">
        <span th:text="${item}">Default</span>
    </li>
</ul>

这篇关于如何将列表从控制器发送到百里香叶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆