Commit ebdc118a by Patryk Czarnik

Wypełnianie formularza danymi produktu

parent 49e148c6
...@@ -72,7 +72,21 @@ public class ProductController { ...@@ -72,7 +72,21 @@ public class ProductController {
} }
@GetMapping("/{id}/edit") @GetMapping("/{id}/edit")
public String editProduct(@PathVariable("id") Integer productId) { public String editProduct(Model model, @PathVariable("id") Integer productId) {
// W tej metodzie ładujemy dane istniejącego produktu i przechodzimy do formularza
Optional<Product> product = productRepository.findById(productId);
if(product.isPresent()) {
model.addAttribute("product", product.get());
return "product_form";
} else {
model.addAttribute("product_id", productId);
return "missing_product";
}
}
@GetMapping("/new")
public String newProduct() {
// W tej metodzie wyświetlamy pusty formularz
return "product_form"; 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