Thymeleaf passing 2 parameters to URL

1

Good evening guys,

I have the following problem:

I'm trying to pass 2 parameters to the URL using Thymeleaf, but I'm not able to retrieve the value of the variable "name" to pass the second parameter.

Note: Euconsigo pass the page number.

Could you please 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>
    
asked by anonymous 26.08.2018 / 00:12

1 answer

0

I solved the problem.

URL assembly was wrong. The correct would be:

th:href="@{/produtos/listar?page=${i}&nome=${nome}}"
    
26.08.2018 / 00:20