基於flex4技術從零開發flex部落格系統:4 資料存放區

來源:互聯網
上載者:User

通過前三課我艱苦卓絕的努力,用戶端與服務端通訊已經沒有問題了。這對於一個沒有學過flex4,沒有用過java的初學者,已經相當不容易了。到目前為止,開發部落格系統的準備工作,已經僅剩最後一項了:資料存放區。

Google App Engine沒有資料庫的概念,不過app engine提供了JDO儲存介面,google充許開發人員直接定義、儲存、查詢、修改實體(entity)。

一,資料定義

我在sban.flexblog package下添加一個名為Greeting的實體類,這個一個POJO(Plain Old Java Object),意即簡單樸素的java對象。Greeting.java類的代碼如下:

package sban.flexblog;
import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

/**
 * @author sban.li
 *
 */
@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class Greeting {

        @PrimaryKey
        @Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
        private Long id;

        @Persistent
        private String user;

        @Persistent
        private String greetingContent;

        @Persistent
        private Date date;

        public Greeting(String user, String content, Date date)
        {
                this.user = user;
                this.greetingContent=content;
                this.date = date;
        }

        public String getUser()
        {
                return this.user;
        }

        public Long getId()
        {
                return this.id;
        }

        public String getGreetingContent()
        {
                return this.greetingContent;
        }

        public Date getDate()
        {
                return this.date;
        }
}

關於Pojo實體定義的簡要說明:

1,@PrimaryKey用於定義實體的主鍵

2,@Persistent用於標識該變數名 稱將被儲存

3,valueStrategy=IdGeneratorStrategy.IDENTITY設定id為自增模式,這意味著執行個體化該實體類時不用給id賦值

4,identityType=IdentityType.APPLICATION是幹什麼用的,不清楚,暫時不用管它

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.