簡體   English   中英

最簡單的讀/寫谷歌應用引擎的方法

[英]easiest way to read/write to google app engine

我無法弄清楚如何使用谷歌應用引擎保存和讀取數據。 這段代碼沒有編譯,但應該讓你知道我想做什么。 我似乎無法弄清楚的唯一一件事是如何從字符串中創建自己的密鑰....

DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();


    Entity article = new Entity("Article", "keyThatIMadeUp");

    article.setProperty("articleHTML", "this is where the article html goes");


    datastore.put(article);
    try {
        Entity articleRetrieved = datastore.get(Key("keyThatIMadeUp"));
    }
    catch (EntityNotFoundException e) {
        System.out.println("data not found");
    }

任何幫助都會非常感謝!

密鑰嵌入了他們關鍵的實體類型。 因此,要從部件重建密鑰,您需要提供實體類型的名稱。 在你的情況下,你正在尋找類似的東西

... = datastore.get(Key.from_path("Article", "keyThatIMadeUp"))

請嘗試以下ndb概述。 它有一個你可以遵循的簡單例子。

https://developers.google.com/appengine/docs/python/ndb/overview

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM