关键是,您不需要动手就可以使用org.bson.document。
Morphia将在幕后为您完成所有这些工作。
import com.mongodb.MongoClient;import org.mongodb.morphia.Datastore;import org.mongodb.morphia.DatastoreImpl;import org.mongodb.morphia.Morphia;import java.net.UnknownHostException;..... private Datastore createDataStore() throws UnknownHostException { MongoClient client = new MongoClient("localhost", 27017); // create morphia and map classes Morphia morphia = new Morphia(); morphia.map(FooBar.class); return new DatastoreImpl(morphia, client, "testmongo"); }...... //with the Datastore from above you can save any mapped class to mongo Datastore datastore; final FooBar fb = new FooBar("hello", "world"); datastore.save(fb);
在这里,您会找到几个示例:https :
//mongodb.github.io/morphia/
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)