【问题标题】:Thymeleaf: "Exception evaluating OGNL expression" in a simple for loopThymeleaf:一个简单的 for 循环中的“异常评估 OGNL 表达式”
【发布时间】: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 上的某个地方有一个骗局 - 我现在找不到它......
  • 就是这样!谢谢????
  • 很高兴是这样。我找不到骗子,所以我添加了一个答案,以防它对未来的访问者有所帮助。

标签: kotlin thymeleaf javalin


【解决方案1】:

尝试将votes-positive 更改为不使用连字符的内容。这被解释为 OGNL 减法表达式中的减号。

【讨论】:

    猜你喜欢
    • 2017-04-20
    • 1970-01-01
    • 1970-01-01
    • 2017-09-20
    • 1970-01-01
    • 1970-01-01
    • 2016-12-19
    • 2016-09-27
    • 1970-01-01
    相关资源
    最近更新 更多