Answer the question
In order to leave comments, you need to log in
How to get the data of one object from the database and apply it to normal html tags in Thymeleaf?
How to get the fields of a certain object by its id and display its separate field in thymeleaf, for example, in the tag ?
At the moment, I have all this displayed in a table that is in a form, but I do not want to have a form with a table, I would like to apply the received object fields to regular tags, for example, apply the data of the name field to the tag
I would like to have something in html something like this:
there is an object model:
private int id;
private int idFace;
private String name;
private String town;
private String idType;
private String post;
private Date birthday;
private String contacts;
private String description;
private String family;
private String postIndex;
private Long itn;
public Optional<Contact> get(int id) {
return contactRepository.findById( id);
}
@GetMapping("/face/{id}")
public ModelAndView editProductForm(@PathVariable(name = "id")int id) {
ModelAndView mav = new ModelAndView("view_face");
Optional contact = contactService.get(id);
mav.addObject("contact", contact);
return mav;
}
<form action="#" th:object="${contact}" method="post">
<table border="0" cellpadding="10">
<tr>
<td>Product ID:</td>
<td><input type="text" th:field="*{id}" readonly="readonly"></td>
</tr>
<tr>
<td>Product Name:</td>
<td><input type="text" th:field="*{name}"></td>
</tr>
</table>
</form>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question