Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在表格中显示多行_Java_Spring Boot_Thymeleaf - Fatal编程技术网

Java 在表格中显示多行

Java 在表格中显示多行,java,spring-boot,thymeleaf,Java,Spring Boot,Thymeleaf,我正在尝试使用Spring Boot应用程序上的ThymileAF创建一个活动参与者表 我的桌子看起来像这样: <table class="table table-bordered tabl-striped"> <thead class="thead-dark"> <th>First Name</th> <th>Last Name</th>

我正在尝试使用Spring Boot应用程序上的ThymileAF创建一个活动参与者表

我的桌子看起来像这样:

<table class="table table-bordered tabl-striped">
    <thead class="thead-dark">
        <th>First Name</th>
        <th>Last Name</th>
    </thead>
    <tbody>
        <tr th:each="tempEvent : ${event}">
            <td th:text="${tempEvent.clubEventAttendees[event].firstName}" />
            <td th:text="${tempEvent.clubEventAttendees[event].lastName}" />
        </tr>
    </tbody>
</table>
此输出包含正确的数据。然而,上表只列出了我的第二位与会者(卢克·斯迈思)。如果我将td行更改为:

<td th:text="${tempEvent.clubEventAttendees[0].firstName}" />
<td th:text="${tempEvent.clubEventAttendees[0].lastName}" />
注意:已删除getter和setter

我目前有一个页面,其中列出了所有事件(在表格中):


一旦我弄清楚这一点,“与会者”列将被删除,但如果单击“查看与会者”按钮,我希望看到一个页面,其中包含一个类似的表格,但包含所有与会者的名字、姓氏、电话和手机。基本上,我希望获取clubEventAttendees中返回的数据,并将其显示在与上表类似的表中。

好的,正如承诺的那样,下面是代码

我可以用
Person
Car
来解释这个例子。这个想法是
拥有
列表

按下View Cars(查看车辆)后,将打开一个新页面,您将看到一个车辆列表

如何实现这一点相当简单。从modelAttribute
people
呈现
List
时,可以使用以下代码

<tr th:each="person : ${people}">
                <td th:text="${person.id}"></td>
                <td th:text="${person.firstName}"></td>
                <td th:text="${person.lastName}"></td>
                <td>
                    <a th:href="@{'/person/' + ${person.id} + '/cars'}">View Cars</a>
                </td>
</tr>
之后将呈现一个新模板。我在GitHub上上传了源代码,可以在这里找到


希望能有所帮助,如果还有其他内容,请告诉我。

您需要添加模型以查看变量类型。您是否可以详细说明实际要显示的内容?是否所有的
clubeventandess
都来自
event
您想要显示的内容?如果您能提供示例,说明响应的外观like@Prebiusta我在问题的底部添加了一些细节。在这种情况下,我将创建
,并在控制器中写入
@GetMapping(“/event/{eventId}/attendeers”)
。在这个控制器方法中,我将访问databsae,并在Path变量中获取给定事件ID的用户,然后返回新的模板HTML文件。这是你想要实现的目标吗?我可以写一个例子是的,听起来很像我想要的。回答得很好。谢谢你花时间帮我拿。非常感谢。
<td th:text="${tempEvent.clubEventAttendees[1].firstName}" />
<td th:text="${tempEvent.clubEventAttendees[1].lastName}" />
<tr th:each="person : ${people}">
                <td th:text="${person.id}"></td>
                <td th:text="${person.firstName}"></td>
                <td th:text="${person.lastName}"></td>
                <td>
                    <a th:href="@{'/person/' + ${person.id} + '/cars'}">View Cars</a>
                </td>
</tr>
@GetMapping("/person/{personId}/cars")
public String getCars(Model model, @PathVariable Integer personId){
    model.addAttribute("cars", carRepository.findAllByPersonId(personId));
    return "web/car-list";
}