java - Thymeleaf:使用#dates.format() 函数来格式化具有国际化的日期。

标签 java spring-mvc thymeleaf

我正在使用 Thymeleaf#dates.format() 函数在 View 层中格式化日期。我为 pic 日期格式创建了一个国际化属性文件。我正在使用 #dates.format(date, (#{app.dateformat})) 这样的函数。但是 Thymeleaf 抛出一个解析异常。因为 thymeleaf 现在解析 app.dateformat。我如何在 thymeleaf 中使用日期格式国际化方式。以下是一个异常(exception):

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.

Source

关于java - Thymeleaf:使用#dates.format() 函数来格式化具有国际化的日期。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28808838/

相关文章:

java - 如何创建一个列表,从另一个对象列表中提取数据

java - Spring Security 在每个页面显示数据

java - 如何使用serialize Collections.synchronizedList和co

java - 用于 noscript 中使用的 spring 模型变量的 thymeleaf 语法

java - Thymeleaf 模板 - 有没有办法装饰模板而不是包含模板片段?

java - 使用 maven 的具有依赖项的可执行 jar

java - 将 org.apache.commons 导入 android 应用程序

spring - 将数据传递到服务层的最佳实践

java - 使用 Thymeleaf 在 Spring Boot 中记录 Activity 的最佳方式是什么?

java - 如何并行执行 cucumber 功能文件