@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"; }