我有一个字符串列表 - 这是我感兴趣的属性名称:
我想加入这些字符串的值,但不是使用属性名称,而是使用它们的属性值。
我看到起点是 #strings.listJoin
- 但我怎么能说要将列表中的元素与它们在属性文件中的值相匹配呢?
列表将是:[name, address]
在我的属性文件中:
name=stg
address=another something
我想获取字符串:stg, another something
最佳答案
您可以使用 #messages.listMsg
和 #strings.listJoin
从您的@Controller 返回模型:
model.addAttribute("messageKeyList", Lists.newArrayList("name", "address"));
您可以像这样加入翻译消息列表:
<div th:text="${#strings.listJoin(#messages.listMsg(messageKeyList), ',')}"></div>
哪个应该产生你所期望的,例如:
Some name,Some address
名称和地址是消息文件中的键。
关于java - 如何在 thymeleaf 中处理和连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22959987/