格式嵌套对胸腺上表的对象
我构建了CRM系统,
我有对象名称用户,他也掌握了详细信息表(一至多个界面)的数据,
让我说我已经嵌套了对象名称用户,他有一个以上的详细信息对象,
我想最终得到这个问题在胸腺桌上 名称|进入日期
David | 5/6/22
David | 1/7/22
,但我得到了
名字|进入日期
David | 5/6/22,1/7/22
这是百里叶上的表代码:
<table class="table w-75 table-striped table-dark table-hover">
<thead>
<tr>
<th scope="col" class="text-center">First name</th>
<th scope="col" class="text-center">Entry Date</th>
</tr>
</thead>
<tbody>
<tr th:each="users : ${ParkingUsers}">
<td class="text-center" th:text="${users.firstName}" />
<td class="text-center" th:each="date, i: ${users.parkingDetails}"
th:text="${(i.index > 0 ? '' : '') + date.entryDate}" />
</tr>
</tbody>
</table>
我该如何解决? 谢谢
i build crm system,
i had object hes name users he hold also the data from details table (one to many realation)
lets says i had nested object name user and he had more than 1 object of details
i want to get this in the end in thymeleaf table
name | entry date
david | 5/6/22
david | 1/7/22
but i got
name | entry date
david | 5/6/22 , 1/7/22
this is table code on thymeleaf:
<table class="table w-75 table-striped table-dark table-hover">
<thead>
<tr>
<th scope="col" class="text-center">First name</th>
<th scope="col" class="text-center">Entry Date</th>
</tr>
</thead>
<tbody>
<tr th:each="users : ${ParkingUsers}">
<td class="text-center" th:text="${users.firstName}" />
<td class="text-center" th:each="date, i: ${users.parkingDetails}"
th:text="${(i.index > 0 ? '' : '') + date.entryDate}" />
</tr>
</tbody>
</table>
how can i fix that?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是使用胸腺
th:
th:块
标签。
您可以将外循环(用于用户)放在此标签中,然后将内部循环(用于停车详细信息)放在
&lt; tr&gt;
标签中。示例:
假设我们有两个类:
和:
假设我们有一个用户列表:
list&lt; user&gt;
。我们可以在胸腺模板中使用以下内容:
这将生成以下html:
th:block
标签允许胸腺eleaf在用户列表上迭代,但并未导致生成任何HTML。th:block
标签在th:block> th:block
内的所有子标签中可以引用th:block
标签中创建的thymeleaf$ {user}
变量。在本网站上的其他问题中,还有其他各种示例可以使用
th:block
- 因此,如果这不满足您的需求,则可以研究其他问题。This is a good candidate for using the Thymeleaf
th:block
tag.You can place the outer loop (for users) in this tag, and then place the inner loop (for parking details) in the
<tr>
tag.Example:
Assume we have two classes:
And:
And assume we have a list of users:
List<User>
.We can use the following in our Thymeleaf template:
This will generate the following HTML:
The
th:block
tag allowed Thymeleaf to iterate over the list of users, but it did not cause any HTML to be generated. The Thymeleaf${user}
variable created in theth:block
tag can be referenced in all the child tags inside theth:block
.There are various other examples of how
th:block
can be used, in other questions on this site - so if this does not meet your needs, you can research those other questions.