如何在百里香叶中将对象 id 设置为分区 id?



我正在尝试将我的对象 id 设置为div id,但是当我尝试运行我的应用程序时,我收到一条错误消息

org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing

堆栈跟踪中的另一个错误:

org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'id' cannot be found on object of type 'io.getstream.core.models.EnrichedActivity' - maybe not public or not valid?

这是我的 html 代码:

<div typeIdFieldName="id" th:id="${#strings.trim(object['id'])}" class="c-default-item" th:each="object : ${objects}"></div>

您正在寻找

th:id="${object.id}"

假设由th:each="object : ${objects}"迭代的列表中的每个对象都包含一个 "id" 属性,一个getId(){...}形状的 getter ,并且模型有一个名为"对象"的对象列表。

问题是io.getstream.core.models.EnrichedActivity有一个getID()getter方法名称,当使用th:id="${object.id}"访问时,将引发异常

org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'id' cannot be found on object of type 'io.getstream.core.models.EnrichedActivity' - maybe not public or not valid?.

为了避免这个错误,我使用了getter方法(th:id="${object.getID()}"(而不是直接访问属性。

最新更新