简体   繁体   中英

Play Java Backbone.js collection

I am using the Play 2 framework to try and set up a simple todo app with Backbone.JS. I found the code on Play's site for handling a single request from backbone.

@BodyParser.Of(BodyParser.Json.class)
public static Result getList() {

    ObjectNode result = Json.newObject();

    String name = " Matt";
    if(name == null) {
        result.put("status", "KO");
        result.put("message", "Missing parameter [name]");
        return badRequest(result);
    } else {
        result.put("status", "Ok");
        result.put("message", "Hello " + name);
        return ok(result);
    }
}

However, I cannot figure out how to return a whole collection. I have tried putting the ObjectNode in an array and returning that. I'm just beginning with restful api's and could use some help. I have searched all over for a solution but have come up empty. I would greatly appreciate some help. Thanks.

You can change your object(including collection) in the JSON, Play has inbuilt Jackson integration

try this

return ok(Json.toJson(obj)); // prepare you object obj and return it like this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM