Commit fdc4b353 by Patryk Czarnik

Użycie @RestController zamiast @Controller

parent e2c4a390
package sklep.rest;
import org.springframework.http.HttpStatusCode;
import org.springframework.stereotype.Controller;
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 org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;
import sklep.model.Product;
import sklep.photo.PhotoUtil;
......@@ -13,7 +9,9 @@ import sklep.repository.ProductRepository;
import java.util.List;
@Controller
// @RestController odpowiada adnotacji @Controller z dodatkową adnotacją @ResponseBody
// Inaczej mówiąc, metody nie zwracają nazw szablonów, lecz dane, które mają być odesłane do klienta.
@RestController
@RequestMapping("/rest/products")
public class ProductEndpoint {
private ProductRepository productRepository;
......@@ -26,13 +24,11 @@ public class ProductEndpoint {
}
@GetMapping
@ResponseBody
public List<Product> getProducts() {
return productRepository.findAll();
}
@GetMapping("/{id}")
@ResponseBody
public Product getProduct(@PathVariable int id) {
return productRepository.findById(id).orElseThrow(
() -> new ResponseStatusException(HttpStatusCode.valueOf(404),
......
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