Commit ebdc118a by Patryk Czarnik

Wypełnianie formularza danymi produktu

parent 49e148c6
......@@ -72,10 +72,24 @@ public class ProductController {
}
@GetMapping("/{id}/edit")
public String editProduct(@PathVariable("id") Integer productId) {
return "product_form";
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";
}
@GetMapping(path="/{id}/photo", produces="image/jpeg")
@ResponseBody
public byte[] getPhoto(@PathVariable("id") Integer productId) {
......
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