Thymeleaf:使用#dates.format() 函数来格式化具有国际化的日期。
Thymeleaf: Use #dates.format() function for format date with internatinalization.
我正在使用 Thymeleaf #dates.format()
函数在视图层中格式化日期。我为 pic 日期格式创建了一个国际化属性文件。我正在使用这样的 #dates.format(date, (#{app.dateformat}))
函数。但是 Thymeleaf
抛出一个解析异常。因为 thymeleaf 现在解析了 app.dateformat
。我如何在 thymeleaf 中使用日期格式国际化方式。以下是一个例外:
org.springframework.expression.spel.SpelParseException: EL1043E:(pos 37): Unexpected token. Expected 'identifier' but was 'lcurly({)'
您应该改用此语法:
${#dates.format(date, #messages.msg('app.dateformat'))}
#messages
: utility methods for obtaining externalized messages inside variables expressions, in the same way as they would be obtained using #{...} syntax.
我正在使用 Thymeleaf #dates.format()
函数在视图层中格式化日期。我为 pic 日期格式创建了一个国际化属性文件。我正在使用这样的 #dates.format(date, (#{app.dateformat}))
函数。但是 Thymeleaf
抛出一个解析异常。因为 thymeleaf 现在解析了 app.dateformat
。我如何在 thymeleaf 中使用日期格式国际化方式。以下是一个例外:
org.springframework.expression.spel.SpelParseException: EL1043E:(pos 37): Unexpected token. Expected 'identifier' but was 'lcurly({)'
您应该改用此语法:
${#dates.format(date, #messages.msg('app.dateformat'))}
#messages
: utility methods for obtaining externalized messages inside variables expressions, in the same way as they would be obtained using #{...} syntax.