android開發使用greenDAO如何自動產生代碼

來源:互聯網
上載者:User

</pre> 因為看了開源項目中使用greenDAO的ORM架構。今天總算搞清楚是如何自動產生entity,dao等java檔案的了。<p></p><p><span style="white-space:pre"></span>準備工作:需要到greenDAO官網下載jar包,地址為:http://greendao-orm.com/download-and-source/。總共有兩個jar包。<img src="https://img-blog.csdn.net/20150422232323268?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaHVuYW5fbGlqaWVf/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /></p><p><span style="white-space:pre"></span>當然還需要另外一個包:freemarker-2.3.19.jar。</p><p></p><p><span style="white-space:pre"></span>有了三個jar包以後,就可以新建立一個java工程,產生代碼了。</p><p></p><p></p><pre name="code" class="java">package com.test.example;import java.io.IOException;import de.greenrobot.daogenerator.DaoGenerator;import de.greenrobot.daogenerator.Entity;import de.greenrobot.daogenerator.Schema;public class TestDemo {/** * @param args */public static void main(String[] args) {
<span style="white-space:pre"></span> // 第一個參數資料庫版本,第二個參數表示產生java的包名。 Schema schema = new Schema(3, "com.example.greendao.mytest.bean"); addNote(schema); try {
<span style="white-space:pre"></span>// 第二個參數表示組建檔案存放路徑。new DaoGenerator().generateAll(schema, "../src");} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();} System.out.println("ok");} private static void addNote(Schema schema) {        Entity note = schema.addEntity("Note");                         note.addIdProperty();        note.addStringProperty("text").notNull();        note.addStringProperty("comment");        note.addDateProperty("date"); }}

代碼下載地址: 點擊開啟連結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.