thymeleaf get first 3 objects












0















Could you please help me.
I want to display my first 3 objects from product, I don't how it must be.
I try to use thymeleaf sequence, but it don't work. Maybe somebody can hint me how it could be done.



HTML:



<th:block th:each="product:${products}">

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


Controller:



@GetMapping("/products")
public String seeAllProductsIntoAList(Model model){
model.addAttribute("products", productService.findAll());
model.addAttribute("categories", categoryService.findAll());
return "/productView/products";
}


It would be great if somebody can hint me with this issue.



Thank you.










share|improve this question

























  • what will productService.findAll() return ?

    – want2learn
    Nov 28 '18 at 18:53











  • @Override public List<Product> findAll() { return dao.findAll(); }

    – Roman Sychok
    Nov 28 '18 at 18:54
















0















Could you please help me.
I want to display my first 3 objects from product, I don't how it must be.
I try to use thymeleaf sequence, but it don't work. Maybe somebody can hint me how it could be done.



HTML:



<th:block th:each="product:${products}">

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


Controller:



@GetMapping("/products")
public String seeAllProductsIntoAList(Model model){
model.addAttribute("products", productService.findAll());
model.addAttribute("categories", categoryService.findAll());
return "/productView/products";
}


It would be great if somebody can hint me with this issue.



Thank you.










share|improve this question

























  • what will productService.findAll() return ?

    – want2learn
    Nov 28 '18 at 18:53











  • @Override public List<Product> findAll() { return dao.findAll(); }

    – Roman Sychok
    Nov 28 '18 at 18:54














0












0








0








Could you please help me.
I want to display my first 3 objects from product, I don't how it must be.
I try to use thymeleaf sequence, but it don't work. Maybe somebody can hint me how it could be done.



HTML:



<th:block th:each="product:${products}">

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


Controller:



@GetMapping("/products")
public String seeAllProductsIntoAList(Model model){
model.addAttribute("products", productService.findAll());
model.addAttribute("categories", categoryService.findAll());
return "/productView/products";
}


It would be great if somebody can hint me with this issue.



Thank you.










share|improve this question
















Could you please help me.
I want to display my first 3 objects from product, I don't how it must be.
I try to use thymeleaf sequence, but it don't work. Maybe somebody can hint me how it could be done.



HTML:



<th:block th:each="product:${products}">

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


Controller:



@GetMapping("/products")
public String seeAllProductsIntoAList(Model model){
model.addAttribute("products", productService.findAll());
model.addAttribute("categories", categoryService.findAll());
return "/productView/products";
}


It would be great if somebody can hint me with this issue.



Thank you.







java spring spring-mvc spring-boot thymeleaf






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 28 '18 at 19:03







Roman Sychok

















asked Nov 28 '18 at 18:45









Roman SychokRoman Sychok

145




145













  • what will productService.findAll() return ?

    – want2learn
    Nov 28 '18 at 18:53











  • @Override public List<Product> findAll() { return dao.findAll(); }

    – Roman Sychok
    Nov 28 '18 at 18:54



















  • what will productService.findAll() return ?

    – want2learn
    Nov 28 '18 at 18:53











  • @Override public List<Product> findAll() { return dao.findAll(); }

    – Roman Sychok
    Nov 28 '18 at 18:54

















what will productService.findAll() return ?

– want2learn
Nov 28 '18 at 18:53





what will productService.findAll() return ?

– want2learn
Nov 28 '18 at 18:53













@Override public List<Product> findAll() { return dao.findAll(); }

– Roman Sychok
Nov 28 '18 at 18:54





@Override public List<Product> findAll() { return dao.findAll(); }

– Roman Sychok
Nov 28 '18 at 18:54












2 Answers
2






active

oldest

votes


















2














Since products is list of Product, you have to iterate over that list. On thymeleaf you can use th:each attribute to do iteration. So for your case you can use something as below. Give it a try.



<th:each="product,iterStat: ${products}" th:if="${iterStat.index} <3">


I am not entirely sure but based on your question you wanted only first three objects. For this you can use status variable that are defined in th:each. More detail you can find here.






share|improve this answer


























  • If this solve your problem, don't forget to mark my answer as correct answer.

    – want2learn
    Nov 28 '18 at 21:23



















0














Here's the way you do it with the #{numbers} context object.



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





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53526117%2fthymeleaf-get-first-3-objects%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Since products is list of Product, you have to iterate over that list. On thymeleaf you can use th:each attribute to do iteration. So for your case you can use something as below. Give it a try.



    <th:each="product,iterStat: ${products}" th:if="${iterStat.index} <3">


    I am not entirely sure but based on your question you wanted only first three objects. For this you can use status variable that are defined in th:each. More detail you can find here.






    share|improve this answer


























    • If this solve your problem, don't forget to mark my answer as correct answer.

      – want2learn
      Nov 28 '18 at 21:23
















    2














    Since products is list of Product, you have to iterate over that list. On thymeleaf you can use th:each attribute to do iteration. So for your case you can use something as below. Give it a try.



    <th:each="product,iterStat: ${products}" th:if="${iterStat.index} <3">


    I am not entirely sure but based on your question you wanted only first three objects. For this you can use status variable that are defined in th:each. More detail you can find here.






    share|improve this answer


























    • If this solve your problem, don't forget to mark my answer as correct answer.

      – want2learn
      Nov 28 '18 at 21:23














    2












    2








    2







    Since products is list of Product, you have to iterate over that list. On thymeleaf you can use th:each attribute to do iteration. So for your case you can use something as below. Give it a try.



    <th:each="product,iterStat: ${products}" th:if="${iterStat.index} <3">


    I am not entirely sure but based on your question you wanted only first three objects. For this you can use status variable that are defined in th:each. More detail you can find here.






    share|improve this answer















    Since products is list of Product, you have to iterate over that list. On thymeleaf you can use th:each attribute to do iteration. So for your case you can use something as below. Give it a try.



    <th:each="product,iterStat: ${products}" th:if="${iterStat.index} <3">


    I am not entirely sure but based on your question you wanted only first three objects. For this you can use status variable that are defined in th:each. More detail you can find here.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 28 '18 at 19:17

























    answered Nov 28 '18 at 19:01









    want2learnwant2learn

    1,17011125




    1,17011125













    • If this solve your problem, don't forget to mark my answer as correct answer.

      – want2learn
      Nov 28 '18 at 21:23



















    • If this solve your problem, don't forget to mark my answer as correct answer.

      – want2learn
      Nov 28 '18 at 21:23

















    If this solve your problem, don't forget to mark my answer as correct answer.

    – want2learn
    Nov 28 '18 at 21:23





    If this solve your problem, don't forget to mark my answer as correct answer.

    – want2learn
    Nov 28 '18 at 21:23













    0














    Here's the way you do it with the #{numbers} context object.



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





    share|improve this answer




























      0














      Here's the way you do it with the #{numbers} context object.



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





      share|improve this answer


























        0












        0








        0







        Here's the way you do it with the #{numbers} context object.



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





        share|improve this answer













        Here's the way you do it with the #{numbers} context object.



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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 28 '18 at 19:37









        MetroidsMetroids

        7,48421326




        7,48421326






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53526117%2fthymeleaf-get-first-3-objects%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)