gpt4 book ai didi

java - 如何在 spring mvc 中用 thymeleaf 填充一个简单的表

转载 作者:行者123 更新时间:2023-11-28 04:54:23 25 4
gpt4 key购买 nike

我有一个对象列表,我想使用 thymeleaf 在表格中显示这些对象的值,这是我目前所拥有的:

这是我的 Controller 类,它添加了我的对象列表:

@RequestMapping(value = "/showTableWithValues", method = RequestMethod.GET)
public String showTableWithValues(Model model)
{
//list with Persons
ArrayList<Persons> personsList=
new ArrayList<Persons>();

personsList= this.getListOfPersons();

model.addAttribute("list", personsList);

return "showTableWithValues";
}

这是我的 .html 文件,我想在其中显示我的值:

<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">

<head>
<title>Home</title>
</head>
<body>
<h1>
Show Values
</h1>

<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Cost</th>
<th>Mins to prepare</th>
<th>Action</th>
</tr>
</thead>
<tbody>

<tr th:each="persons : ${list}">

</tr>

</tbody>
</table>
</body>
</html>

还有我的 Person.java 类:

public class Person {

private String name;
private String last_name;
private String nickname;



.....get,setters and constructor
}

最佳答案

您缺少 <TD>提供模板的标签在哪里打印哪些字段。查看Iteration Basics of the documentation

关于java - 如何在 spring mvc 中用 thymeleaf 填充一个简单的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25942358/

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