February 2018
Intermediate to advanced
406 pages
9h 55m
English
Here, instead of POST, we will use a PUT method indicating the ID of the product to be updated in the URL pattern. Like the POST method, the details of the product to be updated are provided in the @RequestBody annotation:
@RequestMapping(value="/product/{id}", method = RequestMethod.PUT) ResponseEntity<Product> updateProduct(@PathVariable("id") int id, @RequestBody Product product) { // First fetch an existing product and then modify it. Product existingProduct = prodRepo.findOne(id); // Now update it back existingProduct.setCatId(product.getCatId()); existingProduct.setName(product.getName()); Product savedProduct = prodRepo.save(existingProduct) ; // Return the updated product with status ok return new ResponseEntity<Product>(savedProduct, ...Read now
Unlock full access