Spring Boot Restful Web Service and CRUD Operations using H2 In-Memory Practical Demo Session 14

Welcome back friends! In the Previous Post Previous Post(Session13) we have seen how to configure H2 in Memory DB. In this post we will going to implement various end point to perform CRUD Operation
Following endpoint implemented in my controller class

This is for adding new Product in the H2 DB
@PostMapping("/add") // http://localhost:8080/api/products/add
    public void add(@RequestBody Product product) {
        productService.saveProduct(product);
    }
This method for view a particular product by passing productId
@GetMapping("/{productId}") // http://localhost:8080/api/products/2
    public Product getProduct(@PathVariable Long productId) {
        System.out.println("getProduct::starts");
        Product product = productService.getProduct(productId);
        return product;
    }
This method for updating particular product 
@PutMapping("/{productId}")  // http://localhost:8080/api/products/3
    public Product updateProduct(@RequestBody Product newProduct, @PathVariable Long productId) {
        System.out.println("updateProduct::starts");
        Product product = productService.saveProduct(newProduct);
        return product;
    }
Following two methods for delete particular Product and deleting all product from DB
@DeleteMapping() // http://localhost:8080/api/products
    public String deleteAllProducts() {
        System.out.println("deleteAllProducts::starts");
        productService.deleteProducts();
        return "All Products are deleted";
    }
@DeleteMapping("/{productId}")
public void deleteProduct(@PathVariable Long productId) {
System.out.println("deleteProduct::starts");
productService.deleteProduct(productId);
}

The complete source code is available @ Following GitHub Repository.
https://github.com/sureshstalin/itgarden/tree/master/SpringBoot14
Watch this full video for complete understanding CRUD Operation


Buy our hygiene Napkin. Our Napkins are chemical-free napkin and it has three categories.
Wings Napkin – This napkin wrapped around pure cotton cloth
https://pinepad.in/product/hygiene-eco-friendly-biodegradable-large-size-pure-cotton-cloth-wrapped-sanitary-napkin/
Wingless Napkin

https://pinepad.in/product/hygiene-eco-friendly-biodegradable-large-size-sanitary-pad-pack-4-32-pads/
Maternity Napkin for new Moms
https://pinepad.in/product/hygiene-eco-friendly-and-biodegradable-maternity-pad-pack-of-4-24-pads/ 

Close Menu
×
×

Cart