Get parameter in POST controller spring with thymeleaf

Viewed 57

first sorry for my english! and i hope somebody can help me.

I need to get the parameter ${producto.nombre} in the POST controller i tried with RequestParam etc but nothing works fine.

The thing is that i have the values already settled, but i want to make a post with the data in the producto view.

I have this in "producto.html"

<th:block th:each="producto: ${producto}">
  <div class="col-sm-6">
    <img th:src="@{'data:image/jpg;base64,'+${producto.base64imagen}}" class="img-fluid"/>
</div>
    <div class="col-sm-6">
     <form th:action="@{/productos/{id}(id=${producto.id})}" method="post">
       <input type="hidden" name="pref" th:value="${pref}" id="preferencia"/>
        <div class="nombreproducto" th:text=${producto.nombre}></div>
        <div class="precioproducto" th:text="'$'+${producto.precio}"></div>
        <div class="detallesproducto"  th:text=${producto.detalles}></div>
        <div class="cantidadproducto">Cantidad:<div class="cantidad" th:text=${producto.cantidad}></div></div>
  <div class="comprar"><button type="submit" id="submit" class="btn btn-warning" onclick="checkout.open()">Comprar</button></div>
    </div>
    </form>
   </th:block>

and the two controllers GET:

@RequestMapping(value="/{id}", method=RequestMethod.GET)
    public String productoPorNombre(@PathVariable int id,Model model) {
        model.addAttribute("producto", productorepositorio.findById(id));
        return "producto";
    }

@RequestMapping(value="/id", method=RequestMethod.POST)
    public String productoPorNombrePOST(@RequestParam String nombre,RedirectAttributes redirAttrs,Model model) {
  String productfromhtml=nombre;
  //some code
    return "producto";
  }

0 Answers
Related