我在DAO的方法,它看起来像这样如何在MongoDB和Java中返回对象的ArrayList?
ProductDao.java
public List<Document> getAllProducts() {
return mongoCollection.find().into(new ArrayList<Document>());
}
我想什么,而不是为
//return a list of Product instead of Document
public List<Product> getAllProducts() {
return mongoCollection.find().into(new ArrayList<Product>());
}
的pom.xml
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.3.0</version>
</dependency>
我该如何做到这一点?
渴望尝试Morphia。看起来很有希望。它是MongoDB的子项目吗? – user2325154
是的,它是一个子项目,Morphia建立在最初的mongodb java驱动程序之上。它就像一个包装它。 –