@RequestMapping(value = "/{id}", method = RequestMethod.DELETE) public @ResponseBody String delete(@PathVariable("id") Long id) { if (dao.exists(id)) { dao.delete(id); return "200 OK"; } else { return "ID NOT FOUND : " + id; } }
@RequestMapping(value = "/{id}", method = RequestMethod.PUT) public @ResponseBody String update(@PathVariable("id") Long id, @RequestBody Message e) { if (dao.exists(id)) { dao.save(e); return "200 OK"; } else { return create(e); } }
@RequestMapping(method = RequestMethod.POST) public @ResponseBody String create(@RequestBody Message e) { try { dao.save(e); } catch (Exception ex) { return "Failed: " + ex.getMessage(); } return "200 OK"; }
@RequestMapping(value = "/{id}", method = RequestMethod.GET) public @ResponseBody Message read(@PathVariable("id") Long id) { return dao.findOne(id); }