Java thymeleaf获取前3个对象
你能帮帮我吗。 我想显示产品中的前3个对象,我不知道它必须是什么样子。 我尝试使用thymeleaf序列,但它不起作用。也许有人能告诉我怎么做 HTML: 如果有人能提示我这个问题,那就太好了Java thymeleaf获取前3个对象,java,spring,spring-mvc,spring-boot,thymeleaf,Java,Spring,Spring Mvc,Spring Boot,Thymeleaf,你能帮帮我吗。 我想显示产品中的前3个对象,我不知道它必须是什么样子。 我尝试使用thymeleaf序列,但它不起作用。也许有人能告诉我怎么做 HTML: 如果有人能提示我这个问题,那就太好了 谢谢。因为产品是产品的列表,所以您必须迭代该列表。在thymeleaf上,您可以使用th:each属性进行迭代。因此,对于您的情况,您可以使用以下内容。试试看 <th:each="product,iterStat: ${products}" th:if="${iterStat.index} <
谢谢。因为
产品
是产品
的列表,所以您必须迭代该列表。在thymeleaf上,您可以使用th:each
属性进行迭代。因此,对于您的情况,您可以使用以下内容。试试看
<th:each="product,iterStat: ${products}" th:if="${iterStat.index} <3">
我不完全确定,但根据你的问题,你只想要前三件物品。为此,您可以使用在
th:each
中定义的状态变量。您可以找到更多详细信息。由于产品
是产品
的列表,因此您必须迭代该列表。在thymeleaf上,您可以使用th:each
属性进行迭代。因此,对于您的情况,您可以使用以下内容。试试看
<th:each="product,iterStat: ${products}" th:if="${iterStat.index} <3">
我不完全确定,但根据你的问题,你只想要前三件物品。为此,您可以使用在
th:each
中定义的状态变量。您可以找到更多详细信息。以下是处理{numbers}
上下文对象的方法
<th:block th:each="i: ${#numbers.sequence(0, 2)}" th:with="product=${products[i]}">
<a th:class="production_Page" th:href="@{'product/'+${product.id}}">
<p th:text="${product.productName}"/>
</a>
<a th:class="production_Page" th:href="@{'productDelete/'+${product.id}}">Delete</a>
<a th:class="production_Page" th:href="@{'productEdit/'+${product.id}}">Edit</a>
<img th:class="productImage" th:src="${product.pathImage}"/>
<br/>
</th:block>
以下是使用{numbers}
上下文对象的方法
<th:block th:each="i: ${#numbers.sequence(0, 2)}" th:with="product=${products[i]}">
<a th:class="production_Page" th:href="@{'product/'+${product.id}}">
<p th:text="${product.productName}"/>
</a>
<a th:class="production_Page" th:href="@{'productDelete/'+${product.id}}">Delete</a>
<a th:class="production_Page" th:href="@{'productEdit/'+${product.id}}">Edit</a>
<img th:class="productImage" th:src="${product.pathImage}"/>
<br/>
</th:block>
什么将productService.findAll()
return?@Override public List findAll(){return dao.findAll();}什么将productService.findAll()
return?@Override public List findAll(){return dao.findAll();}