【发布时间】:2021-09-15 22:45:54
【问题描述】:
我有这个控制器:
it.render(
"my-list.html",
mapOf(
"votes-positive" to repo.votesOf("x"),
)
)
//...
data class Vote(
val name: String,
val type: Type,
) {
enum class Type { POS, NEG }
}
我的模板文件"my-list.html:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<div th:each="vote : ${votes-positive}">
<span th:text="${vote.name}"></span>
</div>
</body>
运行时出现此错误,这让我抓狂:
[qtp119358627-23] ERROR org.thymeleaf.TemplateEngine - [THYMELEAF][qtp119358627-23] Exception processing template "my-list.html": Exception evaluating OGNL expression: "vote.name" (template: "my-list.html" - line 21, col 15)
org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating OGNL expression: "vote.name" (template: "my-list.html" - line 21, col 15)
是否有 Thymleaf 调试模式?有没有办法打印模型树?我不知道为什么表达错误。
【问题讨论】:
-
尝试将
votes-positive更改为不使用连字符的内容。这被解释为 OGNL 减法表达式中的减号。在 SO 上的某个地方有一个骗局 - 我现在找不到它...... -
就是这样!谢谢????
-
很高兴是这样。我找不到骗子,所以我添加了一个答案,以防它对未来的访问者有所帮助。