如何在循环 thymeleaf 中连接 2 个值

How to concat 2 values inside a loop thymeleaf

我在 thymeleaf 中连接 2 个值时遇到一些问题

我执行以下操作:

<tr th:each="p , in: ${info}">
<td th:utext="${p.nombre}">...</td>
<td th:utext="${p.preferencias.get(0).getNombrePref()} +'-'+ ${p.preferencias.get(1).getNombrePref()}">...</td>
<td th:utext="${p.email}">...</td>
</tr>

This is how the page looks like

如您所见,这不是动态的,因为如果 p.preferencias 大小大于 2,这将是一个问题,如果小于 2

,则同样如此

这是我尝试过的:

<tr th:each="p , in: ${info}">
<td th:utext="${p.nombre}">...</td>
<td th:each="a , arcd : ${p.preferencias}" th:utext="${p.preferencias.get(arcd.index).getNombrePref()}">...</td>
<td th:utext="${p.email}">...</td>
</tr>

这是我得到的:

And got this

如您所见,第二个值移动到电子邮件 :( 然后我想在连接值中尝试这个 :

<tr th:each="p , in: ${info}">
<td th:utext="${p.nombre}">...</td>
<td th:each="a , arcd : ${p.preferencias}" th:utext="${p.preferencias.get(arcd.index).getNombrePref()} + '-' +${p.preferencias.get(arcd.index).getNombrePref()} " >...</td>
<td th:utext="${p.email}">...</td>
</tr>

这是结果:

Result 3

我不知道如何连接值并将它们保存在一个单元格中 我如何执行循环以获取 p.preferencias 变量内的所有值?

编辑: post 结果 3 中的错误图像现在是正确的图像

最终解决问题标签 td 保持打开状态,这就是为什么每次迭代中的第二个值填充下一个单元格使用 span 标签解决它并在

内迭代
<tr th:each="p , in: ${info}">
    <td th:utext="${p.nombre}">...</td>
    <td>
        <span th:each="a , arcd : ${p.preferencias}" th:utext="${p.preferencias.get(__${arcd.index}__).getNombrePref()} +  (${arcd.size-1 > arcd.index}? ', ':'')"></span>
    </td>
    <td th:utext="${p.email}">...</td>
</tr>

Output