Commit 4cc275e3 by Patryk Czarnik

automatyczne zapisywanie w modelu

parent 446dc71b
......@@ -13,7 +13,6 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import jakarta.persistence.Column;
import sklep.model.Product;
import sklep.photo.PhotoUtil;
import sklep.repository.ProductRepository;
......@@ -71,10 +70,13 @@ public class ProductController {
@PostMapping({ "/new", "/{id}/edit" })
public String zapiszProdukt(Model model, Product product) {
System.out.println("Obiekt przed zapisem: " + product.getProductId() + " " + product.getProductName());
// W tej wersji dane z wypełnionego formularza odbieramy w postaci jednego obiektu Product.
// Spring sam wpisze dane do pól o takich samych nazwach.
// Taki parametr od razu staje się częścią modelu (to jest tzw. ModelAttribute)
// System.out.println("Obiekt przed zapisem: " + product.getProductId() + " " + product.getProductName());
productRepository.save(product);
System.out.println("Obiekt po zapisie: " + product.getProductId() + " " + product.getProductName());
model.addAttribute("product", product);
return "product_form";
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment