Created
November 12, 2012 03:38
-
-
Save andrei-m/4057362 to your computer and use it in GitHub Desktop.
Example of Spring MVC handlers that work with https://github.com/andrei-m/backbone-demo
This file contains 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
@RequestMapping(value="/backboneAccounts", method=RequestMethod.GET) | |
@InternalApi | |
public ResponseEntity<String> getBackboneAccounts() { | |
JSONArray resultJson = new JSONArray(); | |
JSONObject account1 = new JSONObject(); | |
JSONObject account2 = new JSONObject(); | |
JSONObject account3 = new JSONObject(); | |
try { | |
account1.put("id", 1); | |
account1.put("name", "Foo Account"); | |
account1.put("status", "Active"); | |
account2.put("id", 2); | |
account2.put("name", "Bar Account"); | |
account2.put("status", "Paused"); | |
account3.put("id", 3); | |
account3.put("name", "Baz Account"); | |
account3.put("status", "Active"); | |
} catch (JSONException e) { | |
e.printStackTrace(); | |
} | |
resultJson.put(account1); | |
resultJson.put(account2); | |
resultJson.put(account3); | |
HttpHeaders headers = new HttpHeaders(); | |
headers.setContentType(MediaType.APPLICATION_JSON); | |
return new ResponseEntity<String>(resultJson.toString(), headers, HttpStatus.OK); | |
} | |
@RequestMapping(value="/backboneAccounts/{id}", method=RequestMethod.PUT) | |
@InternalApi | |
public ResponseEntity<String> putBackboneAccount(@PathVariable String id, @RequestBody String body) { | |
LOGGER.info(body); | |
return new ResponseEntity<String>("", new HttpHeaders(), HttpStatus.OK); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment