Persistence with Spring and Thymeleaf in multiple tables in the same form

0

I have another vision

How can I pass two objects in the ModelAndView so that when calling a save request, I can do this distribution of objects for each Entyti.

I have Entyti Client and Contact, in page I need to save the past values, being redistributed according to object mapped in ModelAndView.

EX.

* {contact.email} - would be saved to the contact  * {name} - would be saved on the client;

Remembering that I'm using Thymelealf in the form.

    
asked by anonymous 03.12.2018 / 19:31

1 answer

0

You can reference the object and attribute directly in the form element rather than just defining a th: object for the whole form, for example:

<form class="form-horizontal" th:method="POST" th:action="@{/cadastrar}">
   <div class="form-group">
      <input type="text" class="form-control" id="email" th:field="${contato.email}"/>
   </div>
   <div class="form-group">
      <input type="text" class="form-control" id="nome" th:field="${cliente.nome}"/>
   </div>
   <div class="form-group">
      <button type="submit" class="btn btn-primary">Salvar</button>
   </div>
</form>

After that, you only need to save the two objects per parameter in your controller.

    
07.12.2018 / 20:36