0
I have a page that shows all blog posts. This page has a posting object that in turn has the attribute that is a list of categories.
This list of categories is shown on the page in the form links to each post inserted on the page for the end user. The end user can click on a link and then it is directed to a page that contains all posts related to that category link theme.
I want to use the th:each
to assemble the links.
Links are assembled but incorrectly!!
Here’s how he gets:
http://localhost:8084/spring-thymeleaf/categoria/?jpa
assuming the user clicked on the "jpa" link generated by the code below:
<div th:each="categoria: ${postagem.categorias}">
<a href="#"th:href="@{/categoria/(${categoria.permalink})}">
<span th:text="${categoria.descricao}"></span></a>
</div>
I want to value the content of ${categoria.permalink}
but without having that infamous interrogation!
To get to this my code I based on an example of the site itself Thymeleaf:
<tr th:each="prod : ${prods}" th:class="${prodStat.odd}? 'odd'">
<td th:text="${prod.name}">Onions</td>
<td th:text="${prod.price}">2.41</td>
...
<span th:text="${#lists.size(prod.comments)}">2</span> comment/s
<a href="comments.html"
th:href="@{/product/comments(prodId=${prod.id})}"
th:unless="${#lists.isEmpty(prod.comments)}">view</a>
</td>
</tr>
That generates the following url:
http://localhost:8084/gtvg/product/comments?prodId=9
I wish it was possible to use the following code
<div th:each="categoria: ${postagem.categorias}">
<a href="#"th:href="@{/categoria/${categoria.permalink}}">
<span th:text="${categoria.descricao}"></span></a>
</div>
But it has the following output, when I click on the link "jpa":
http://localhost:8084/spring-thymeleaf-jsp/categoria/$%7Bcategoria.permalink%7D
Here’s the excerpt from my controller that handles the request:
@RequestMapping(value = "/categoria/{link}", method = RequestMethod.GET)
public ModelAndView postsByCategoria(@PathVariable("link") String link, ModelMap model) {
List<Postagem> postagens = postagemService.findByCategoria(link);
model.addAttribute("postagens", postagens);
return new ModelAndView("posts.html", model);
}
What should I do? I’ve searched many places and nothing!!
Apparently the
?
is coming straight from the value of${categoria.permalink}
. How this value is generated?– Woss
Try to use
<a href="#" th:href="@{/categoria/{link}(link=${categoria.permalink})}">
, has more in the documentation– Woss
@Andersoncarloswoss At last! Phew! Thank you very much!! Put as a reply compadre!! Ai fica explicito para quem passar pelo mesmo probleminha inha!!
– Pena Pintada