下面的代码片段显示了如何当您遍历结果中提取一个文件的各个字段的查询。如果你愿意,你可以把每个领域放在一个GUI的文本框中。
完整的代码示例是在这里:https://gist.github.com/3087822
private static void queryAndDisplayStudents(DBCollection students)
{
// Get all students (no query criteria).
DBCursor cursor = students.find();
// Iterate over the students.
while (cursor.hasNext())
{
// Display each student.
DBObject student = cursor.next();
// Get the individual fields of the student document.
// These individual fields could, for example,
// be put in text fields of a GUI.
String name = (String) student.get("Name");
Number sid = (Number) student.get("SID");
String university = (String) student.get("University");
// Given that we are not actually building a GUI,
// just display the fields on the command line.
System.out.printf("Student name: %s, SID: %d, University: %s%n",
name, sid, university);
}
}
谢谢伊恩工程:) – jad001 2012-07-15 01:04:30
如果什么文件嵌套像 '“名称”:{“名”:“鲍勃”,”第二个名字“:”Lien“}, ”SID“:10,”University“:”INA“' 现在如何在文本框中显示'Name'文档(嵌套),上面给出的代码是为了简单文件,现在我想显示嵌套或嵌入式文件的数据。我希望你能理解我的问题。 – jad001 2012-07-25 18:52:36
plz帮我嵌套一个?如果文档嵌套,我们将如何访问java中的嵌套文档? – jad001 2012-07-27 20:38:55