1
Good evening, everyone,
I have the following problem:
I am trying to pass 2 parameters in the URL using Thymeleaf, but I am not able to recover the value of the variable "name" to pass in the second parameter.
Note: Euconsigo pass the page number.
Please, could you help me?
Controller:
@GetMapping("/listar")
public String listar(@RequestParam(name = "nome", defaultValue = "") String nome,
@RequestParam(name = "page", defaultValue = "0") int page, ModelMap model) {
if (!nome.isEmpty()) {
model.addAttribute("produtos", produtoService.findByNome(PageRequest.of(page, 5), nome));
model.addAttribute("nome", nome);
} else {
model.addAttribute("produtos", produtoService.listarTodos(PageRequest.of(page, 5)));
}
model.addAttribute("currentPage", page);
return "produto/lista";
}
HTML I want to pass the parameters:
<ul class="pagination" style="text-align: center">
<li class="waves-effect"
th:each="i: ${#numbers.sequence(0, produtos.totalPages-1)}"><a
th:href="@{/produtos/listar/(page=${i}, nome=${nome})}"
th:text="${i}"
th:classappend="${currentPage}==${i}?'button_actions_back':''"></a></li>
</ul>