【发布时间】:2021-06-22 19:48:28
【问题描述】:
我正在努力在 Thymeleaf 的列表过滤器中使用枚举值。
我知道如何迭代枚举值以及如何将它们与常量值进行比较。但是,我想将它与“变量”值进行比较。我怎样才能实现它?
在下面的示例中,我想遍历所有颜色(枚举),然后按当前颜色枚举过滤汽车列表并显示它们的名称。
如何正确指定第二个<div>中的列表过滤器?
<div th:each="currentColorEnum : ${T(de.my.enum.color).values()}">
<div th:each="currentCar, carStatus : ${model.carList.?[#this.colorEnum eq __${currentColorEnum}__]}">
<textarea th:field="*{carList[__${carStatus.index}__].carName}"></textarea>
</div>
</div>
当前错误信息:
org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'red' cannot be found on object of type 'de.my.class.car' - maybe not public or not valid?
【问题讨论】: