Thymeleaf: Can I use messages inside expressions

◇◆丶佛笑我妖孽 提交于 2019-12-22 17:59:36

问题


I am using Thymeleaf 3 within a Spring Boot application. Currently I am in a situation where I want to use a message expression inside an EL expression (Spring EL).

First use case: trim the message

data:title="${#{message.key}.trim()}

Second use case: conditionally create an attribute with a message as its value

data:title="${condition ? #{message.key} : ''}

Both examples will produce a syntax error, because #{ is not an allowed start of an expression.

Any ideas how to achieve what I want?


回答1:


In both cases you'll want to use the #messages utility object.

data:title="${#messages.msg('key').trim()}"

data:title="${condition ? #messages.msg('key') : ''}"


来源:https://stackoverflow.com/questions/48231060/thymeleaf-can-i-use-messages-inside-expressions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!