我在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驅動程序之上。它就像一個包裝它。 –