老司机带你学习GreenDao3

2017-06-21  本文已影响73人  予以摩卡
我知道你们没有图是不会进来的,就是简单的greenDao3的增删改查 和完全自动化升级字段且保留之前的数据!
IMG_0049.JPG
   buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:2.0.0'
    classpath 'org.greenrobot:greendao-gradle-plugin:3.1.0'
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' //这个是黄油刀的注解

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
  }
}
      apply plugin: 'com.android.application'
      apply plugin: 'org.greenrobot.greendao'
    android {
      compileSdkVersion 23
      buildToolsVersion "25.0.0"
      
      
        buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}
//greendao配置
greendao {
    schemaVersion 6                       //版本号,升级时可配置
    daoPackage 'star.liuwen.com.endgreendao3.Dao'     //包名
    targetGenDir 'src/main/java'                 //生成目录
  
  
  
dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  testCompile 'junit:junit:4.12'
  compile 'com.android.support:appcompat-v7:23.0.1'
  compile 'org.greenrobot:greendao:3.2.0'
}

@Entity
public class Test {
    @Id
    private Long id;
    private int url;
    private String name;
    private String desc;
}

public class MySQLiteOpenHelper extends DaoMaster.OpenHelper {


    public MySQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory) {
        super(context, name, factory);
    }

    @Override
    public void onUpgrade(Database db, int oldVersion, int newVersion) {
        Log.e("greenDAO",
                "Upgrading schema from version " + oldVersion + " to " + newVersion + " by migrating all tables data");
         //完全自动升级本地数据库 要升级那个bean 只需要调用下面这个方法 
        // MigrationHelper.getInstance().migrate(db, xxx.class);
        MigrationHelper.getInstance().migrate(db, TestDao.class);
    }
}

https://github.com/liuwen370494581/greenDao3

喜欢的盆友麻烦点个赞 非常感谢了。。。。
上一篇 下一篇

猜你喜欢

热点阅读