我一直在关注本指南http://www.thymeleaf.org/doc/articles/springmvcaccessdata.html以了解如何使用 Thymeleaf 将数据模型呈现到 Springboot 应用程序中。我有一个函数可以从我的 Parse-Server 检索对象列表并将它们呈现为模型属性:
@RequestMapping(value = "/requests", method = RequestMethod.GET)
public String findRequestsByCurrentUser(Model model) {
ParseUser currentUser = ParseUser.getCurrentUser();
log.info(String.valueOf(currentUser.getObjectId()));
findRequestsByCurrentUser(model, currentUser);
return "requests";
}
private void findRequestsByCurrentUser(Model model, ParseUser currentUser) {
ParseQuery<ParseObject> requestsQuery = ParseQuery.getQuery("Request");
requestsQuery.whereContains("author", currentUser.getObjectId());
requestsQuery.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> requestList, ParseException e) {
if (e == null) {
model.addAttribute("requests", requestList);
}
}
});
}
这是我发送到我的视图的模型的调试:
出于某种原因,我可以渲染currentRole
得很好。但是我无法从requests
模式部分渲染任何单个属性。我应该使用request.data.requestStatus
orrequest.requestStatus
吗?即使${request}
单独也不会渲染整个对象。我尝试了几种不同的方法。似乎没有一个工作。这是我的 HTML:
<center>
<table class="table table-striped">
<tr>
<td><b>Requested By</b></td>
<td><b>Reason</b></td>
<td><b>Requested Date</b></td>
<td><b>Status</b></td>
</tr>
<tr th:each="request : ${requests}">
<div th:switch="${request.data.requestStatus}">
<div th:case="Approved">
<td th:text="${request.author.objectId" class="initial-name">Employee Initials
</td>
<td th:text="${request.requestText}">Request Description</td>
<td th:text="${request.dateRequested}">Request Date</td>
<td th:switch="${request.requestStatus}">
<span class="red" th:case="Pending"
th:text="Pending">Status</span>
<span class="green" th:case="Approved"
th:text="Approved">Status</span>
<span class="red" th:case="Rejected"
th:text="Rejected">Status</span>
</td>
</div>
</div>
</tr>
</table>
</center>
在我的 HTML 中,我遍历 requestList 中提供的请求对象,然后检索它们的属性。
Thymeleaf 是否敏感,如果我在 HTML 中的任何地方有一个错字,所有对象都不会呈现?还有什么问题?我需要将我的 ParseObject 转换为 Java 对象吗?我需要传递 ArrayList 而不是 List 吗?
问题似乎在于列表本身的呈现。我从 HTML 中删除了所有属性,只为列表提供了静态文本。它应该渲染了 15 行静态文本,但它根本不渲染任何东西......我想知道它可能是什么。