Commit 4d81ff36 by Patryk Czarnik

Przeniesienie adresu /products na poziom klasy

parent a413d668
...@@ -9,6 +9,7 @@ import org.springframework.stereotype.Controller; ...@@ -9,6 +9,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import sklep.model.Product; import sklep.model.Product;
...@@ -16,18 +17,19 @@ import sklep.repository.ProductRepository; ...@@ -16,18 +17,19 @@ import sklep.repository.ProductRepository;
import sklep.util.PhotoUtil; import sklep.util.PhotoUtil;
@Controller @Controller
@RequestMapping("/products")
public class ProductController { public class ProductController {
@Autowired @Autowired
private ProductRepository productRepository; private ProductRepository productRepository;
@GetMapping("/products") @GetMapping
public String readAll(Model model) { public String readAll(Model model) {
List<Product> products = productRepository.findAll(); List<Product> products = productRepository.findAll();
model.addAttribute("products", products); model.addAttribute("products", products);
return "products"; return "products";
} }
@GetMapping("/products/{numer}") @GetMapping("/{numer}")
public String readOne(Model model, @PathVariable Integer numer) { public String readOne(Model model, @PathVariable Integer numer) {
Optional<Product> product = productRepository.findById(numer); Optional<Product> product = productRepository.findById(numer);
...@@ -40,7 +42,7 @@ public class ProductController { ...@@ -40,7 +42,7 @@ public class ProductController {
} }
} }
@GetMapping("/products/szukaj") @GetMapping("/szukaj")
public String szukaj(Model model, public String szukaj(Model model,
String name, String name,
BigDecimal min, BigDecimal min,
...@@ -69,7 +71,7 @@ public class ProductController { ...@@ -69,7 +71,7 @@ public class ProductController {
return "wyszukiwarka2"; return "wyszukiwarka2";
} }
@GetMapping(path="/products/{id}/photo", produces="image/jpeg") @GetMapping(path="/{id}/photo", produces="image/jpeg")
@ResponseBody @ResponseBody
public byte[] getPhoto(@PathVariable("id") Integer productId) { public byte[] getPhoto(@PathVariable("id") Integer productId) {
return photoUtil.readBytes(productId); return photoUtil.readBytes(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