gpt4 book ai didi

java - 无法使用 Thymeleaf 渲染对象 : Property or field cannot be found on object of type 'org.parse4j.ParseObject' - maybe not public?

转载 作者:行者123 更新时间:2023-11-30 02:35:34 25 4
gpt4 key购买 nike

我一直在关注本指南 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, TmtUser currentUser) {
ParseQuery<ParseObject> requestsQuery = ParseQuery.getQuery(ParseConstantsUtil.CLASS_REQUEST);
requestsQuery.whereContains(ParseConstantsUtil.REQUEST_AUTHOR, currentUser.getObjectId());
try {
List<ParseObject> requestsArrayList = requestsQuery.find();
model.addAttribute("requests", requestsArrayList);
log.info(String.valueOf(requestsArrayList));
log.info(String.valueOf(requestsArrayList.size()));
} catch (ParseException e) {
e.printStackTrace();
}
}

这是我发送到 View 的模型的调试:

enter image description here

我能够渲染对象,因为我可以包含静态文本而不是其属性,并且它将循环 15 次(查询中检索到的对象数量)。但每当我输入 request.requestTextrequest.requestStatus 时,我都会收到错误:

<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.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>

异常(exception):

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'requestText' cannot be found on object of type 'org.parse4j.ParseObject' - maybe not public?
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:207) ~[spring-expression-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:96) ~[spring-expression-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
at org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:48) ~[spring-expression-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
at org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:358) ~[spring-expression-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88) ~[spring-expression-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:120) ~[spring-expression-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:267) ~[spring-expression-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
at org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:263) ~[thymeleaf-spring5-3.0.3.M1.jar:3.0.3.M1]
... 116 common frames omitted

为什么 Thymeleaf 无法访问 ParseObject 属性?

当我单独打印 ${request} 时,我得到:org.parse4j.ParseObject@5975192b,例如。我还可以检索 ${request.objectId}。检索属性的语法是什么? ${request.data.requestText} 似乎也不起作用...

最佳答案

当使用 Hashmap 访问模型属性时,它可以工作,无需创建自定义 ParseObject:

<td th:text="${request.get('requestText')}">Request Description</td>

关于java - 无法使用 Thymeleaf 渲染对象 : Property or field cannot be found on object of type 'org.parse4j.ParseObject' - maybe not public?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43201951/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com