英文:
MongoDB Pojo get anonimos class
问题
我有一个Java项目,其中我使用MongoDB,
我使用pojoCodeRegistery
我为我的项目创建了一个小的辅助类,我的问题是:
这个可以正常工作:
public MongoCollection<Client> getClientsCollection() {
MongoDatabase db = client.getDatabase(dbNAme);
return db.getCollection("clients", Client.class);
}
但我想实现这个:
public MongoCollection<SomeClass> getSomeClassCollection(String collectionName, Class someClass) {
MongoDatabase db = client.getDatabase(dbNAme);
return db.getCollection(collectionName, SomeClass.class);
}
有什么建议吗?
英文:
I've have a java project where i use MongoDB,
I use pojoCodeRegistery
i have created a small helper class for my project and my question is :
this works fine :
public MongoCollection<Client> getClientsCollection() {
MongoDatabase db = client.getDatabase(dbNAme);
return db.getCollection("clients", Client.class);
}
``
but i want to achieve this :
public MongoCollection<SomeClass> getSomeClassCollection(String collectionName,Class someClass) {
MongoDatabase db = client.getDatabase(dbNAme);
return db.getCollection("clients", SomeClass.class);
}
Any advise ?
</details>
专注分享java语言的经验与见解,让所有开发者获益!
评论