thymeleaf get first 3 objects
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
add a comment |
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
what willproductService.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
add a comment |
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
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
java spring spring-mvc spring-boot thymeleaf
edited Nov 28 '18 at 19:03
Roman Sychok
asked Nov 28 '18 at 18:45
Roman SychokRoman Sychok
145
145
what willproductService.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
add a comment |
what willproductService.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
add a comment |
2 Answers
2
active
oldest
votes
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.
If this solve your problem, don't forget to mark my answer as correct answer.
– want2learn
Nov 28 '18 at 21:23
add a comment |
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>
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
If this solve your problem, don't forget to mark my answer as correct answer.
– want2learn
Nov 28 '18 at 21:23
add a comment |
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.
If this solve your problem, don't forget to mark my answer as correct answer.
– want2learn
Nov 28 '18 at 21:23
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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>
add a comment |
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>
add a comment |
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>
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>
answered Nov 28 '18 at 19:37
MetroidsMetroids
7,48421326
7,48421326
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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