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

Asked

Viewed 244 times

0

I have another vision

How can I pass two objects in Modelandview, so that when calling a request to save I can do this object distribution for each Entyti.

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

EX.

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

Remembering that I am using Thymelealf in the form.

1 answer

0

You can reference the object and attribute directly in the form element instead of setting only one th:Object for the entire 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 just receive in your controller’s save method the two objects per parameter.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.