Created
June 2, 2014 14:15
-
-
Save scottcagno/29d7a281924bb10020f5 to your computer and use it in GitHub Desktop.
Example REST style controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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