小编Mat*_*mer的帖子

Google App Engine Objectify - 加载单个对象或键列表?

我正在努力掌握Go​​ogle App Engine编程,并想知道这两种方法之间的区别是什么 - 如果有实际差异的话.

方法A)

public Collection<Conference> getConferencesToAttend(Profile profile)
{
    List<String> keyStringsToAttend = profile.getConferenceKeysToAttend();
    List<Conference> conferences = new ArrayList<Conference>();
    for(String conferenceString : keyStringsToAttend)
    {
        conferences.add(ofy().load().key(Key.create(Conference.class,conferenceString)).now());
    }
    return conferences; 
}
Run Code Online (Sandbox Code Playgroud)

方法B)

public Collection<Conference> getConferencesToAttend(Profile profile)
    List<String> keyStringsToAttend = profile.getConferenceKeysToAttend();
    List<Key<Conference>> keysToAttend = new ArrayList<>();
    for (String keyString : keyStringsToAttend) {
        keysToAttend.add(Key.<Conference>create(keyString));
    }
    return ofy().load().keys(keysToAttend).values();
}
Run Code Online (Sandbox Code Playgroud)

"conferenceKeysToAttend"列表保证只有唯一的会议 - 即使我选择了两种备选方案中的哪一种呢?如果是这样,为什么?

java google-app-engine objectify

3
推荐指数
1
解决办法
1229
查看次数

标签 统计

google-app-engine ×1

java ×1

objectify ×1