1.导依赖
buildscript {
repositories {
jcenter()
mavenCentral() // 第一步. add repository
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'org.greenrobot:greendao-gradle-plugin:3.3.0' //第二步. add plugin
}
apply plugin: 'org.greenrobot.greendao' // 第三步.apply plugin
dependencies {
implementation 'org.greenrobot:greendao:3.3.0' // 第四步.add library
}
//第五步
greendao {
// 指定数据库schema版本号,迁移等操作会用到
schemaVersion 1
// 设置生成数据库文件的目录,默认是在build中,可以将生成的文件放到我们的java目录中
targetGenDir 'src/main/java'
// 设置生成的数据库相关文件的包名,默认为entity所在的包名
daoPackage 'com.yoho.greendao.gen' //自己创建的那个包的路径}
2.创建实体类
3.创建一个包,包名根据自己
4.点击 然后自动生成三个类
5.创建一个类 根据生成的参加数据库名
6.使用单列 用类名点出那个方法 然后再点增删改查
//添加
//查询
//删除 修改