event.eventStart
是一个OffsetDateTime对象。
添加到POM
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
将Java8TimeDialect添加到模板引擎
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')}"