2

here 问之间有什么区别:使用物化时有什么区别?

Profile profile = ofy().load().type(Profile.class).id(userId).now(); 

Profile profile = ofy().load().key(Key.create(Profile.class, userId)).now(); 

为什么我们必须创建使用Key.create(Profile.class, userId) userId的关键? 谢谢。

回答

2

唯一的区别是第一个示例通过隐式定义密钥来执行密钥查询。第二个显式定义了密钥。

两者都会导致非常相同的关键查询。

您不必为显式地为userId创建密钥。但这样做更明显你在做什么。