java - 如何在 thymeleaf 中处理和连接字符串

标签 java thymeleaf

我有一个字符串列表 - 这是我感兴趣的属性名称: 我想加入这些字符串的值,但不是使用属性名称,而是使用它们的属性值。 我看到起点是 #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/

相关文章:

java - 在 Java 8 中使用 Lambda 从 Map of Maps 生成 Map

spring-boot - Thymeleaf - 获取经过身份验证的用户的全名

JavaScript 不适用于 bootstrap 4 + thymeleaf

java - Thymeleaf 忽略未找到的片段

Java 正则表达式不工作 - 为什么?

java - 对象实例化 : Inner class and outer class with the same name (Java)

java - cURL 有效,但 Apache 的 HttpComponents 库中的相同请求不起作用?

java - 带通知的 Activity 导航

java - 如何在 Spring + Thymeleaf 上添加弹出窗口

java - 如何在 Thymeleaf 和 Spring 中设置选定的选项