格式嵌套对胸腺上表的对象

发布于 2025-01-29 03:23:45 字数 1002 浏览 3 评论 0原文

我构建了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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

违心° 2025-02-05 03:23:45

这是使用胸腺 th:th:块标签。

您可以将外循环(用于用户)放在此标签中,然后将内部循环(用于停车详细信息)放在&lt; tr&gt;标签中。

示例:

假设我们有两个类:

public class User {

    private String firstName;
    private List<ParkingDetail> parkingDetails;

    // getters and setters

}

和:

public class ParkingDetail {

    private LocalDate entryDate;

    // getters and setters
    
}

假设我们有一个用户列表:list&lt; user&gt;

我们可以在胸腺模板中使用以下内容:

<table class="table w-75 table-striped table-dark table-hover">
    <thead>
        <tr>
            <th>First name</th>
            <th>Entry Date</th>
        </tr>
    </thead>
    <tbody>
    <th:block th:each="user : ${users}">
        <tr th:each="parkingDetail : ${user.parkingDetails}">
            <td th:text="${user.firstName}"></td>
            <td th:text="${parkingDetail.entryDate}"></td>    
        </tr>   
    </th:block>
    </tbody>        
</table>

这将生成以下html:

<table>
    <thead>
        <tr>
            <th>First name</th>
            <th>Entry Date</th>
        </tr>
    </thead>
    <tbody>
            
        <tr>
            <td>david</td>
            <td>2022-06-05</td>    
        </tr>
        <tr>
            <td>david</td>
            <td>2022-07-01</td>    
        </tr>   
            
    </tbody>        
</table>

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:

public class User {

    private String firstName;
    private List<ParkingDetail> parkingDetails;

    // getters and setters

}

And:

public class ParkingDetail {

    private LocalDate entryDate;

    // getters and setters
    
}

And assume we have a list of users: List<User>.

We can use the following in our Thymeleaf template:

<table class="table w-75 table-striped table-dark table-hover">
    <thead>
        <tr>
            <th>First name</th>
            <th>Entry Date</th>
        </tr>
    </thead>
    <tbody>
    <th:block th:each="user : ${users}">
        <tr th:each="parkingDetail : ${user.parkingDetails}">
            <td th:text="${user.firstName}"></td>
            <td th:text="${parkingDetail.entryDate}"></td>    
        </tr>   
    </th:block>
    </tbody>        
</table>

This will generate the following HTML:

<table>
    <thead>
        <tr>
            <th>First name</th>
            <th>Entry Date</th>
        </tr>
    </thead>
    <tbody>
            
        <tr>
            <td>david</td>
            <td>2022-06-05</td>    
        </tr>
        <tr>
            <td>david</td>
            <td>2022-07-01</td>    
        </tr>   
            
    </tbody>        
</table>

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 the th:block tag can be referenced in all the child tags inside the th: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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文