java如何使用thymeleaf在html中传递对象
顾客。html
<div class="table-responsive">
<form data-toggle="validator" role="form" th:action="@{/customers}" method="post" th:object="${user}">
<table class="table table-bordered">
<thead>
<tr>
<th>Row</th>
<th>First Name</th>
<th>Last Name</th>
<th>Create Date</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr th:action="@{/customers}" method="post">
<td th:value="${info.firstName}">firstName</td>
<td th:value="${info.lastName}">lastName</td>
<td th:value="${info.createdate}">createdate</td>
<td th:value="${info.emailaddress}">emailaddress</td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
控制器。爪哇
@RequestMapping(value = "/customers", method = RequestMethod.GET)
public String customers(Model model) throws Exception {
String firstName = "prasoon";
String lastName = "gupta";
String createdate = "2 july";
String emailaddress = "prasoon.gupta@abc.com";
List<Customers> info = scheduleService.getCustomer();
model.addAttribute("info", info);
return "pages/customers";
}
# 1 楼答案
我的第一个问题是,如果这些字符串没有添加到模型中,您需要为它们定义什么
这里有一个在thymeleaf中迭代列表的示例
关于你刚才问我的问题,我认为你对自己的架构不太了解。你希望从你的信息列表中得到什么
要在你的列表中添加额外的客户,因此在你的模型中,你必须这样做,但我仍然认为这是一个糟糕的技术