gpt4 book ai didi

thymeleaf - 将对象列表映射到 thymeleaf 中的字符串列表

转载 作者:行者123 更新时间:2023-12-04 13:19:37 25 4
gpt4 key购买 nike

我有一个 User 对象列表,我想将它转换为一个名称列表,加入它并呈现它(不是在表格中)。我该怎么做?

class User {
String name;
String address;
}

我有 usersList,我想将其转换为姓名列表,如下所示:

<body>
<h1>Names of Users</h1>
<span>
<div th:text="${#strings.listJoin(usersList.map( u -> u.name).collect(Collectors.toList()), ',')}"></div>
</span>
</body>

我怎样才能在 thymeleaf 中做到这一点?

最佳答案

您可以使用 collection projection 执行此操作:

<body>
<h1>Names of Users</h1>
<span>
<div th:text="${#strings.listJoin(usersList.![name], ',')}" />
</span>
</body>

关于thymeleaf - 将对象列表映射到 thymeleaf 中的字符串列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55265019/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com