Commit 4d81ff36 by Patryk Czarnik

Przeniesienie adresu /products na poziom klasy

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