Skip to content

Instantly share code, notes, and snippets.

@scottcagno
Created June 2, 2014 14:15
Show Gist options
  • Select an option

  • Save scottcagno/29d7a281924bb10020f5 to your computer and use it in GitHub Desktop.

Select an option

Save scottcagno/29d7a281924bb10020f5 to your computer and use it in GitHub Desktop.
Example REST style controller
@Controller
public class ResourceRestController {
@RequestMapping(value="/resource/item", method=RequestMethod.GET)
@ResponseBody
public String list() {
return "list items hit";
}
@RequestMapping(value="/resource/item", method=RequestMethod.POST)
@ResponseBody
public String insert() {
return "insert item hit";
}
@RequestMapping(value="/resource/item/{id}", method=RequestMethod.GET)
@ResponseBody
public String find(@PathVariable(value="id") Long id) {
return "find item " + id + " hit";
}
@RequestMapping(value="/resource/item/{id}", method=RequestMethod.POST)
@ResponseBody
public String modify(@PathVariable(value="id") Long id, @RequestParam(value="req", required=true) String req) {
switch(req) {
case "delete":
return "delete item" + id + " hit";
case "update":
return "update item" + id + " hit";
default:
return "error modifying item " + id;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment