How do I correctly use RESTful delete in Spring MVC controller? I have DAO that returns boolean when trying to delete some item.
I am trying to delete item. If everything was OK, just show list of items (deleted item won't be there anymore). If item cannot be removed, redirect to details page and say why it couldn't be deleted.
Do I need some special response status or something like this? Is my approach RESTful?
@RequestMapping(value = "items/{id}", method = RequestMethod.DELETE) public String delete(@PathVariable("id") int itemId, Model model) { Item item = itemDao.get(id); // true -> can delete // false -> cannot delete, f.e. is FK reference somewhere boolean wasOk = itemDao.delete(item); if (wasOk) { return "redirect:/items"; } // will write to user which item couldn't be deleted model.addAttribute("item", item); return "items/error"; }