Play! 2 Rendering JSON data in View from Controller

时间:2015-07-28 22:23:21

标签: java scala playframework playframework-2.0 scala-2.10

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

1 个答案:

答案 0 :(得分:1)

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>