【发布时间】:2017-03-02 15:02:44
【问题描述】:
Spring-boot v1.4.1
Java v1.8
Thymeleaf v2.1.5.
我认为下面这行代码:
<td th:each = "sprint : ${sprints}" th:text = "${sprint.releaseDate} ? ${#temporals.format(sprint.releaseDate, 'MMM/dd/yyyy')}"></td>
我基于 S.O. 的语法。问题SpringBoot Thymeleaf Ordinal Numbers,
产生错误:
org.springframework.expression.spel.SpelEvaluationException: EL1011E:(pos 11): Method call: 试图调用方法 空上下文对象上的格式(java.time.LocalDate,java.lang.String)
但是,如果我在没有 Thymeleaf 格式的情况下运行这行代码,它可以工作并以默认格式(“2016-05-25”)呈现 LocalDate 对象表。
问题:为什么会出现“空上下文对象”错误,这是什么意思?以及如何编辑以获得我想要的格式?
【问题讨论】:
-
#temporals 似乎与 thymeleaf-extras-java8time 相关,是否包含在 Spring Boot 配置中?如果不是,您将收到错误消息,因为 #temporals 解析为 null 并且它正在尝试在 null 对象上运行 .format。
-
看起来我正在运行 v2.1.5,我需要 v3 来运行 extras 模块。 github.com/thymeleaf/thymeleaf-extras-java8time
-
Thymeleaf 2.1 有一个 2.1.0.RELEASE 版本(需要 2.1.3+)
标签: java spring spring-boot thymeleaf date-formatting