MongoDB Pojo 获取匿名类

huangapple 未分类评论42阅读模式
英文:

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&lt;Client&gt; getClientsCollection() {
        MongoDatabase db = client.getDatabase(dbNAme);
        return db.getCollection(&quot;clients&quot;, Client.class);
   } 

   
``
but i want to achieve this :
   
  public MongoCollection&lt;SomeClass&gt; getSomeClassCollection(String collectionName,Class someClass) {
               
       MongoDatabase db = client.getDatabase(dbNAme);
       return db.getCollection(&quot;clients&quot;, SomeClass.class);
  }

Any advise ?

</details>


huangapple
  • 本文由 发表于 2020年7月26日 19:14:13
  • 转载请务必保留本文链接:https://java.coder-hub.com/63099351.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定