【发布时间】:2014-12-26 20:11:03
【问题描述】:
在以下 thymeleaf 代码中,我想将列表 produtos 中显示的项目数限制为特定数字:
<div class="col-xs-6 col-lg-4" th:each="item2 : ${produtos}" th:if="${item.getId() == item2.getCategoria().getId()}">
<h2 th:text="${item2.getNome()}"></h2>
<div class="row">
<div class="col-xs-6 col-md-3">
<a th:href="@{/produto/__${item2.getId()}__.htm}" class="thumbnail">
<img th:src="@{/Produto/icone__${item2.getId()}__.jpeg}" width="64" height="64" th:alt="${item2.getNome()}"/>
</a>
</div>
</div>
<p th:text="${#strings.substring(item2.getDescricao(), 0, 140)}"></p>
<p><a class="btn btn-default" th:href="@{/produto/__${item2.getId()}__.htm}" role="button">Detalhes »</a></p>
</div>
但在官方文档中我找不到任何说明如何执行此操作的内容。任何人都可以提供任何提示吗?
更新
我尝试将这个添加到我的代码中来解决这个问题:
th:if="${itemStat.index < NUM}"
最后的代码是这样的:
<div class="col-xs-6 col-lg-4" th:each="item2 : ${produtos}" th:if="${item2Stat.index < NUM}" th:if="${item.getId() == item2.getCategoria().getId()}">
但我收到此错误:
org.xml.sax.SAXParseException: the value of the attribute "th:if" associated to an element "null" shouldn't have the character '<'.
【问题讨论】:
标签: java spring spring-boot thymeleaf