如何在百里香中处理和连接琴弦 [英] How to process and join string in thymeleaf
问题描述
我有一个字符串列表-这些是我感兴趣的属性名称:我想加入这些字符串的值,但不使用属性名称,而是使用它们的属性值.我看到起点是#strings.listJoin
-但是如何说要使列表中的元素与属性文件中的值相匹配?
I have a list of strings - which are the properties names that I am interested in:
I want to join the values of these strings, but not using the properties name, but the properties values for them.
I saw that the starting point is #strings.listJoin
- but how can I say to match the elements in the list against their value in the properties files?
列表将是: [名称,地址]
,并且在属性文件中,我具有:
The list would be: [name, address]
and in the properties file I have:
name=stg
address=another something
我想获取字符串: stg,另一个东西
推荐答案
您可以使用#messages.listMsg
和#strings.listJoin
具有从您的@Controller返回的模型:
Having the model returned from your @Controller:
model.addAttribute("messageKeyList", Lists.newArrayList("name", "address"));
您可以像这样加入翻译后的邮件列表:
You can join list of translated messages like this:
<div th:text="${#strings.listJoin(#messages.listMsg(messageKeyList), ',')}"></div>
应该达到您期望的目标,例如:
Which should produce what you expect, e.g.:
Some name,Some address
名称和地址是邮件文件中的键.
Where name and address are keys in your messages file.
这篇关于如何在百里香中处理和连接琴弦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!