thymeleaf - 在Thymeleaf中动态创建的消息引用?

标签 thymeleaf

所以我有以下代码:

 <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/

相关文章:

spring-boot - Thymeleaf-为表格行创建动态ID

java - Hibernate 和 Thymeleaf 无限递归

java - 为什么 thymeleaf 中的无效反馈不起作用

java - 在 Spring 表达式语言中访问属性文件

javascript - 使用 Thymeleaf 渲染 Spring ModelAndView 对象

java - 无法使用 Spring MVC 在 HTML ArrayList 中打印

spring - 为单个 Spring Boot 实例配置多个模板解析器

java - 使用 Thymeleaf 处理电子邮件 html

javascript - 使用 Thymeleaf 将值通过 AJAX 传递给 Controller ​​,无需任何用户输入

java - Spring boot 创建新行而不是更新