GreenDao3.0简单使用

1.引入greenDao

app的gradle配置

applyplugin:'com.android.application'

applyplugin:'org.greenrobot.greendao'

android{

compileSdkVersion24

buildToolsVersion"24.0.1"

defaultConfig{

applicationId"com.dino.greendaodemo"

minSdkVersion15

targetSdkVersion24

versionCode1

versionName"1.0"

testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"

}

buildTypes{

release{

minifyEnabledfalse

proguardFilesgetDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'

}

}

}

//greendao配置

greendao{

schemaVersion1//版本号,升级时可配置

daoPackage'com.dino.greendaodemo.dao'//包名

targetGenDir'src/main/java'//生成目录

}

dependencies{

compile fileTree(dir:'libs',include:['*.jar'])

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',{

excludegroup:'com.android.support',module:'support-annotations'

})

compile'com.android.support:appcompat-v7:24.2.1'

compile'org.greenrobot:greendao:3.1.1'

}

工程的gradle:

dependencies{

classpath'com.android.tools.build:gradle:2.2.1'

classpath'org.greenrobot:greendao-gradle-plugin:3.1.0'

// NOTE: Do not place your application dependencies here; they belong

// in the individual module build.gradle files

}

2.使用greendao

    新建一个entity.

@Entity//******

publicclassStudent{

@Id//*****主键

privatelongid;

privateStringname;

privateStringsex;

privateintage;

privateStringscore;

}

编译,系统会自动生成需要的各种类.也会自动补全set get方法

你可能感兴趣的:(GreenDao3.0简单使用)