Exemplo n.º 1
0
 @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);
   }
 }
Exemplo n.º 2
0
  @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);
  }