【问题标题】:Thymeleaf: Use #dates.format() function for format date with internatinalization.Thymeleaf:使用#dates.format() 函数来格式化日期并进行国际化。
【发布时间】:2015-03-02 11:35:19
【问题描述】:

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

org.springframework.expression.spel.SpelParseException: EL1043E:(pos 37): Unexpected token. Expected 'identifier' but was 'lcurly({)'

【问题讨论】:

    标签: java spring-mvc thymeleaf


    【解决方案1】:

    你应该改用这个语法:

    ${#dates.format(date, #messages.msg('app.dateformat'))}
    

    #messages :用于在变量表达式中获取外部化消息的实用方法,与使用 #{...} 语法获取它们的方式相同。

    Source

    【讨论】:

    • 我可以在 2.1 版本中使用这个 sintax 吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-26
    • 1970-01-01
    • 1970-01-01
    • 2017-02-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多