所以我有以下代码:
<h3 th:if="#{${'footer.message.' + receiptProperties.url}? : '(NOTHING)'}" th:utext="#{${'footer.message.' + receiptProperties.url}}"></h3>
receiveProperties.url =给租户的名称,例如ABC,DEF等。因此messages.properties文件中的 key 类似于 footer.message.ABC = Hello ABC!
动态创建的消息 key 正确显示,但是,如果属性文件中不存在诸如 footer.message.GHI 之类的 key ,则页面上将显示以下内容: footer.message.GHI_en ??
Thymeleaf中有什么方法可以准确检查属性文件中是否存在动态创建的 key ?
最佳答案
messages utility对象具有可用于此目的的方法。您可以使用类似以下的表达式:
${#messages.msgOrNull('footer.message.' + receiptProperties.url) == null ? 'Invalid key' : 'Valid key'}
关于thymeleaf - 在Thymeleaf中动态创建的消息引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43219970/