Thymeleaf 连接预处理:

Thymeleaf concatenation preprocessing:

我希望有人能帮助我解决 Thymeleaf 的问题。

情况是我需要用 thymeleaf 进行预处理,第一个处理正确,但是在第一个预处理中我需要从模型中获取另一个字段,但是当我在另一个预处理中添加字段 preprocessinf 时给我一个类型错误

无法解析为表达式:"$ {rules ["

如果我这样做,效果很好

rules[__${row.index}__].propertiesValues[]

插入其他预处理失败

rules[__${row.index}__].propertiesValues[__${rules[__${row.index}__].bookingRuleDescriptor.propertyDescriptors[__${iter.index}__].name}__]

希望你能帮帮我。

谢谢!!

只有一个预处理通道。由于 __ 不匹配,您会收到该错误。例如,它第一次尝试预处理:

propertiesValues[__${rules[__${row.index}__]

它尝试计算的表达式是 __${rules[__,这不是有效的 thymeleaf 表达式。

您的选择是:

1) 如果此表达式未在 th:field 中使用,您无论如何都不应该进行预处理。您可以简单地使用:

${rules[row.index].propertiesValues[rules[row.index].bookingRuleDescriptor.propertyDescriptors[iter.index].name]}

2) 如果你在 th:field 中使用它,你必须事先使用 th:with 来评估你的一些表达式。类似于:

<th:block th:with="i=${row.index}, j=${rules[row.index].bookingRuleDescriptor.propertyDescriptors[iter.index].name}">
  <input type="text" th:field="*{rules[__${i}__].propertiesValues['__${j}__']}" />
</th:block>