Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java thymeleaf获取前3个对象_Java_Spring_Spring Mvc_Spring Boot_Thymeleaf - Fatal编程技术网

Java thymeleaf获取前3个对象

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} <

你能帮帮我吗。 我想显示产品中的前3个对象,我不知道它必须是什么样子。 我尝试使用thymeleaf序列,但它不起作用。也许有人能告诉我怎么做

HTML:

如果有人能提示我这个问题,那就太好了


谢谢。

因为
产品
产品
的列表,所以您必须迭代该列表。在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();}