@RequestMapping(value = "/{id}", method = RequestMethod.PUT) @ResponseStatus(HttpStatus.NO_CONTENT) public void updateCommodity(@PathVariable("id") Long id, @RequestBody Commodity commodity) { if (commodityRepository.exists(id)) { commodity.setId(id); commodityRepository.save(commodity); } }
@RequestMapping(method = RequestMethod.POST) public ResponseEntity<String> createCommodity( HttpServletRequest request, @RequestBody Commodity commodity) { commodityRepository.saveAndFlush(commodity); final Long id = commodity.getId(); URI uri = new UriTemplate("{requestUrl}/{id}").expand(request.getRequestURL().toString(), id); final HttpHeaders headers = new HttpHeaders(); headers.put("Location", singletonList(uri.toASCIIString())); return new ResponseEntity<String>(headers, HttpStatus.CREATED); }