【发布时间】:2014-11-14 13:07:14
【问题描述】:
我有一个对象列表,我想使用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
}
【问题讨论】:
-
您忘记在
下添加 。建议你先刷html。
标签: java html spring spring-mvc thymeleaf