예제 #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);
   }
 }
예제 #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);
  }
예제 #3
0
 @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
 @ResponseStatus(HttpStatus.NO_CONTENT)
 public void deleteCommodity(@PathVariable("id") Long id) {
   commodityRepository.delete(id);
 }
예제 #4
0
 @RequestMapping(value = "/{id}", method = RequestMethod.GET)
 public @ResponseBody Commodity read(@PathVariable("id") Long id) {
   return commodityRepository.findOne(id);
 }
예제 #5
0
 @RequestMapping(method = RequestMethod.GET, produces = "application/json")
 @ResponseBody
 public Page<Commodity> listCommodity(Pageable page) {
   return commodityRepository.findAll(page);
 }