作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个对象列表,我想使用 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/
我是一名优秀的程序员,十分优秀!