Thymeleaf:使用#dates.format()函数格式化具有国际化的日期. [英] Thymeleaf: Use #dates.format() function for format date with internatinalization.
问题描述
我正在使用 Thymeleaf#dates.format()
函数在视图层中设置日期格式.我为图片日期格式创建了一个国际化属性文件.我正在使用像这样的#dates.format(date,(#{app.dateformat}))
函数.但是 Thymeleaf
抛出一个解析异常.因为百里香现在可以解析 app.dateformat
.我如何在百里香中使用日期格式国际化方式.以下是一个例外:
I am using Thymeleaf #dates.format()
function for format date in view layer. I create one internatinalization properties file for pic the date format. i am using #dates.format(date, (#{app.dateformat}))
function like this. but Thymeleaf
throw an parse exception. Because thymeleaf now resolve the app.dateformat
. How i use date format internationalization way in thymeleaf. Following is an exception:
org.springframework.expression.spel.SpelParseException: EL1043E:(pos 37): Unexpected token. Expected 'identifier' but was 'lcurly({)'
推荐答案
您应改为使用以下语法:
You should use this syntax instead :
${#dates.format(date, #messages.msg('app.dateformat'))}
#messages
:实用程序方法,用于获取变量表达式内的外部化消息,其方式与使用#{...}语法获得的方式相同.
#messages
: utility methods for obtaining externalized messages inside variables expressions, in the same way as they would be obtained using #{...} syntax.
这篇关于Thymeleaf:使用#dates.format()函数格式化具有国际化的日期.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!