我在 Play 中创建了一个大实体! Java 中的框架,我想只使用 Morphia 和 MongoDB 从数据库中检索特定字段。实体本身很大并且包含很多字段,所以我想通过只检索一个字段来提高我的应用程序的性能。
我知道这是可能的,但我不知道该怎么做...
以下是我的类(class) Shop
中的一些字段:
public String imagePath;
public String profileImagePath;
public String Motto;
@Reference
public Category primeCategory;
public boolean isOnline;
如您所见,primeCategory
字段是我要检索的 Category
实体。
我在 Morphia 的网站上看到了一些可以实现的东西:
Datastore ds = null;
Shop shop = ds.createQuery(Shop.class).retrievedFields(true, "primeCategory").get();
我不确定我到底在这里做什么。
如果有人能向我解释这是否是方法以及我应该如何做,并提供一个例子,那就太好了。
最佳答案
试试这个
Shop.createQuery().retrievedFields(true, "primeCategory").get()
关于java - 如何使用 Java 中的 Morphia 和 Play 框架从实体中检索特定字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12995808/