我有一个对象列表,我想使用thymeleaf
在表格中显示这些对象的值,这是我到目前为止所拥有的:
这是我的控制器类,它添加了我的对象列表:
@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
}
答案 0 :(得分:6)
您缺少<TD>
标签,提供模板要在哪里打印的字段。请参阅Iteration Basics of the documentation
答案 1 :(得分:0)
在<td>
下添加<th>
标记,然后分别使用<td th:text="${persons.ID}"></td>
在表中显示相关数据。