Commit e4c948af by Patryk Czarnik

@Valid

parent 8827f55e
...@@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.PostMapping; ...@@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import jakarta.validation.Valid;
import sklep.model.Product; import sklep.model.Product;
import sklep.photo.PhotoUtil; import sklep.photo.PhotoUtil;
import sklep.repository.ProductRepository; import sklep.repository.ProductRepository;
...@@ -70,7 +71,7 @@ public class ProductController { ...@@ -70,7 +71,7 @@ public class ProductController {
} }
@PostMapping({ "/new", "/{id}/edit" }) @PostMapping({ "/new", "/{id}/edit" })
public String zapiszProdukt(Model model, Product product) { public String zapiszProdukt(Model model, @Valid Product product) {
// W tej wersji dane z wypełnionego formularza odbieramy w postaci jednego obiektu Product. // 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. // Spring sam wpisze dane do pól o takich samych nazwach.
// Taki parametr od razu staje się częścią modelu (to jest tzw. ModelAttribute) // Taki parametr od razu staje się częścią modelu (to jest tzw. ModelAttribute)
......
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