所以,我将Play框架与MongoDB结合使用。我试图将一个列表传递给我的视图,以遍历并显示行。
主计长:
public static Result find() {
List<DBObject> results = MongoController.find(MongoController.getLocalConnection("test"), "jobs");
if (results == null) {
redirect("/");
}
return ok(find_job.render(results));
}上面调用的MongoController使用以下函数(功能测试和测试):
public static List<DBObject> find(DB database, String collectionName) {
DBCursor cursor = database.getCollection(collectionName).find();
List<DBObject> items = new ArrayList<DBObject>();
while (cursor.hasNext()) {
items.add(cursor.next());
}
return items;
}查看:
@(results : List[DBObject])我收到的错误是:
Compilation error:
Not found: type DBObject有人有指点吗?我很抱歉-我对这个框架不熟悉。
发布于 2014-12-15 21:04:38
在将内容导入本地命名空间时,旋转模板的工作方式并不完全相同。默认情况下,只将models包和其他一些播放包导入视图命名空间。之后进行的导入不用于模板参数。
您需要使用完全限定的包名:
@(results: List[com.mongodb.DBObject])或者可以在templateImports中添加build.sbt键。也就是说,将这一行放入您的build.sbt文件中:
TwirlKeys.templateImports += "com.mongodb.DBObject"这将将前面的导入添加到所有已编译的模板中。请注意,这是用来玩2.3.x的。如果使用2.2.x,则应该使用以下方法:
templatesImport += "com.mongodb.DBObject"https://stackoverflow.com/questions/27492989
复制相似问题