gpt4 book ai didi

Java Google App Engine 数据存储区放置/获取

转载 作者:行者123 更新时间:2023-12-01 13:59:50 24 4
gpt4 key购买 nike

看跌期权:

    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
try{
Entity e = new Entity("Winners", "NFL" );
String winner_game = new String("winner_" + input_game );
e.setProperty(winner_game, input_win_value );
datastore.put(e);

...

获取:

    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
try{
Entity e = datastore.get(KeyFactory.createKey("Winners", "NFL" ));
String winner_game = new String("winner_" + i );
if( e.getProperty(winner_game) != null )
{
Integer property = new Integer(e.getProperty( winner_game ).toString());
return property;
}
else{
return 0;
}

...

e.getProperty 返回 null...有什么想法吗?

最佳答案

不要创建新的字符串/整数对象。如果您需要在属性名称中附加一些内容,只需直接执行即可。

Entity e = new Entity("Winners", "NFL" ); 
String winner_game = "winner_" + input_game; // Where input_game is "X"
e.setProperty(winner_game, input_win_value); // int input_win_value = 10;
datastore.put(e);

检索相同:

Entity e = datastore.get(KeyFactory.createKey("Winners",  "NFL" )); 
String winner_game = "winner_" + i; // where i is also "X"
if( e.getProperty(winner_game) != null ) {
// Casting is ugly but does the trick
Integer property = (Integer) e.getProperty(winner_game);
return property;
} else{
return 0;
}

关于Java Google App Engine 数据存储区放置/获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19406400/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com