1,初始化的依赖,参考下面
https://github.com/greenrobot/greenDAO
2,其他学习网址:
http://www.jianshu.com/p/4e6d72e7f57a
http://www.imooc.com/learn/760
3,Application
public class App extends Application {
/** A flag to show how easily you can switch from standard SQLite to the encrypted SQLCipher. */
public static final boolean ENCRYPTED = true;
private DaoSession daoSession;
@Override
public void onCreate() {
super.onCreate();
DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "DB_STUDENT",null);
DaoMaster daoMaster = new DaoMaster(helper.getWritableDatabase());
daoSession = daoMaster.newSession();
}
public DaoSession getDaoSession() {
return daoSession;
}
}
4,代码使用
DaoSession daoSession = ((App) getApplication()).getDaoSession();
mStudentDao = daoSession.getStudentDao();
PersonDao personDao = daoSession.getPersonDao();
5,Bean文件的书写
参考:http://www.jianshu.com/p/4e6d72e7f57a