问题描述
event.eventStart
是OffsetDateTime对象。
已添加到POM
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
将Java8TimeDialect添加到TemplateEngine
final SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.addDialect(new Java8TimeDialect());
<span th:text="${#temporals.format( ${event.eventStart},'yyyy-MM-dd HH:mm:ss ZZZZ')}"></span>
实际-
Expression [#temporals.format( ${event.eventStart},'yyyy-MM-dd HH:mm:ss ZZZZ')] @20: EL1043E: Unexpected token. Expected 'rparen())' but was 'lcurly({)'
解决方法
您不能嵌套${...}
表达式。只需删除中间的多余部分即可。例如:
th:text="${#temporals.format(event.eventStart,'yyyy-MM-dd HH:mm:ss ZZZZ')}"