Skip to content

Instantly share code, notes, and snippets.

@andrei-m
Created November 12, 2012 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrei-m/4057362 to your computer and use it in GitHub Desktop.
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
@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