Commit 71bd7eb7 by Patryk Czarnik

Pojedynczy produkt

parent 71c3a6ec
......@@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sklep.model.Product;
......@@ -18,10 +19,17 @@ public class ProductController {
@Autowired
private EntityManager em;
@GetMapping(produces = "text/plain;charset=UTF-8")
@GetMapping
public String readAll(Model model) {
List<Product> products = em.createNamedQuery("Product.findAll", Product.class).getResultList();
model.addAttribute("products", products);
return "products.jsp";
return "/products.jsp";
}
@GetMapping("/{id}")
public String readOne(@PathVariable("id") Integer productId, Model model) {
Product product = em.find(Product.class, productId);
model.addAttribute("product", product);
return "/product.jsp";
}
}
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