MongoDB Pojo 获取匿名类

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

MongoDB Pojo get anonimos class

问题

我有一个Java项目,其中我使用MongoDB,
我使用pojoCodeRegistery

我为我的项目创建了一个小的辅助类,我的问题是:

这个可以正常工作:

  1. public MongoCollection<Client> getClientsCollection() {
  2. MongoDatabase db = client.getDatabase(dbNAme);
  3. return db.getCollection("clients", Client.class);
  4. }

但我想实现这个:

  1. public MongoCollection<SomeClass> getSomeClassCollection(String collectionName, Class someClass) {
  2. MongoDatabase db = client.getDatabase(dbNAme);
  3. return db.getCollection(collectionName, SomeClass.class);
  4. }

有什么建议吗?

英文:

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 :

  1. public MongoCollection&lt;Client&gt; getClientsCollection() {
  2. MongoDatabase db = client.getDatabase(dbNAme);
  3. return db.getCollection(&quot;clients&quot;, Client.class);
  4. }
  5. ``
  6. but i want to achieve this :
  1. public MongoCollection&lt;SomeClass&gt; getSomeClassCollection(String collectionName,Class someClass) {
  2. MongoDatabase db = client.getDatabase(dbNAme);
  3. return db.getCollection(&quot;clients&quot;, SomeClass.class);
  4. }
  1. Any advise ?
  2. </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:

确定