【发布时间】:2023-02-22 23:59:38
【问题描述】:
这是我的模板,我想列出每个项目的项目 ID。但是不断出错
[# th:each="item : ${items}"]
- [(${item.id})]
[/]
我正在使用 kotlin 代码
val items = listOf(Item(id = "CocaCola123", qty = BigDecimal.ONE))
val templateEngine = TemplateEngine()
val ctx = Context()
ctx.setVariable("item", items)
templateEngine.process(template, ctx)
我收到如下所示的错误
[main] ERROR org.thymeleaf.TemplateEngine - [THYMELEAF][main] Exception processing template "[# th:each="item : ${items}"] - [(${item.id})] [/]": An error happened during template parsing (template: "[# th:each="item : ${items}"]
- [(${item.id})]
[/]")
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "[# th:each="item : ${items}"]
- [(${item.id})]
[/]")
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating OGNL expression: "item.id" (template: "[# th:each="item : ${items}"]
- [(${item.id})]
[/]" - line 2, col 7)
帮助我做错了什么? 我正在关注 thymeleaf 网站处理文本语法的文档。
模板
[# th:each="item : ${items}"]
- [(${item})]
[/]
让我输出
[# th:each="item : ${items}"]
- [Item(id=CocaCola123, qty=1)]
[/]"
我无法访问该 ID
【问题讨论】:
标签: spring-boot kotlin