Pass parameter to Controller in Spring Boot

1

I have a page with a series of images inserted in cells. I have in mind to make that according to which image you click, a common page loads in which within the controller it determines where it comes from. So that according to what image comes, do one thing or another within that common page.

@GetMapping(/comun/¿?¿?¿)
public String paginaComun(){
    if (?¿?parametro?¿? = "imagen1") {
       model.addAttribute("valor", "imagen1");
       return "";
    }
    else if() .......
}

I use Thymealf in case it helps.

    
asked by Eduardo 30.05.2018 в 19:11
source

1 answer

2

You can send a parameter through the url in this way:

 @GetMapping("comun/{parametro}")
    public String paginaComun(
            @PathVariable("parametro") String parametro,
            ModelMap model) {

        /*** SELECCIONAS LA PAGINA QUE QUIERAS MOSTRAR ***/
        model.addAttribute("datos", "Estos son datos!!!");
        return "comun::" + parametro;
    }

And use fragments or the whole page:

return "miPaginaComun";

You can also use ajax. The first example of return comun::fragmento reloads only the template comun that contains a th:fragment="fragmento" .

For the latter you would occupy something like JQuery to send the POST and change to @PostMapping

    
answered by 30.05.2018 / 19:47
source