首页:http://greendao-orm.com/
GreenDAO的使用很像Java中常用的Hibernate框架
Pre-generated code and creating the table
Using the DaoMaster class you can aquire a convenience SQLiteOpenHelper:
new DaoMaster. DevOpenHelper ( this , "notes-db" , null )
Inserting and deleting notes
In the onCreate method we prepare a DAO object:
daoMaster = new DaoMaster(db);
daoSession = daoMaster.newSession();
noteDao = daoSession.getNoteDao();
Now have a look at the addNote method, how you insert a new note in the database:Note note = new Note(null, noteText, comment, new Date());
noteDao.insert(note);
Log.d("DaoExample", "Inserted new note, ID: " + note.getId());
Deleting a note is also straight forward; have a look at the onListItemClick method:
noteDao.deleteByKey(id);
It contains a single class containing the data model definition in code:
Schema schema = new Schema(1, "de.greenrobot.daoexample");
Entity note= schema.addEntity("Note");
note.addIdProperty();
note.addStringProperty("text").notNull();
note.addStringProperty("comment");
note.addDateProperty("date");
new DaoGenerator().generateAll("../DaoExample/src-gen", schema);