Answer the question
In order to leave comments, you need to log in
How to display an object for editing on the page?
I use thymeleaf.
In the controller, I pass an object to the page:
@RequestMapping(value = "/products/edit/{id}", method = RequestMethod.GET)
public String editProduct (@PathVariable Integer id, Model model){
Product product = service.findById(id);
model.addAttribute("product", product);
return "edit";
}
private int id;
private String name;
private String description;
private int price;
private int stock;
<form action="#" th:action="@{/products/edit/{id}" th:object="${product}" method="post">
<input type="number" name="id" th:text="*{id}" />
<input type="text" name="name" th:text="*{name}">
<input type="text" name="description" th:text="*{description}">
<input type="number" name="price" th:text="*{price}">
<input type="number" name="stock" th:text="*{stock}">
<button type="submit">Edit product</button>
</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