简体   繁体   中英

Play! 2 Rendering JSON data in View from Controller

based on this http://www.markhneedham.com/blog/2012/10/14/play-framework-2-0-rendering-json-data-in-the-view/

myview:

    @(message: String)(myobjects:ObjectNode)
@import com.fasterxml.jackson.databind.JsonNode
@import com.fasterxml.jackson.databind.node.ObjectNode

controller:

ObjectNode myobjects = objectsDAO.getObjects();
return ok(myview.render("test",myobjects ));

error

 not found: type ObjectNode

Doesn't seem to work with ObjectNode, the imports in the view don't seem to be working. Could not find much documentation about passing the view a JSON

Try defining it as such: @(message: String, myobjects:com.fasterxml.jackson.databind.node.ObjectNode) , or if that doesn't work, put the @imports in your main.scala.html since it holds the content of your other views....

<body>
    @content
</body>

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