Last active
August 29, 2015 14:17
-
-
Save codegirl-007/88fa2dd8a777cf82f4d9 to your computer and use it in GitHub Desktop.
Return JSON with EBean and Play
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
//return a collection of items | |
public static Result getAssets() { | |
List<Asset> asset = Ebean.find(Asset.class) | |
.findList(); | |
return ok(toJson(asset)); | |
} | |
//or return a single item with the id being passed as a url param | |
public static Result getAsset(Integer id) { | |
Asset asset = Ebean.find(Asset.class, id); | |
if (asset == null) { | |
return internalServerError("Not Found"); | |
} | |
return ok(toJson(asset)); | |
} | |
//or you could even filter by a field in the database | |
public static Result getRoadmaps() { | |
List<Roadmap> roadmaps = Ebean.find(Roadmap.class) | |
.where() | |
.eq("type", "roadmap") | |
.findList(); | |
return ok(toJson(roadmaps)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment