最新版本greenDao V3.2.2的集成与使用(附完整demo)
前言:
使用过GreenDao的同学都知道,3.0之前需要通过新建GreenDaoGenerator工程生成Java数据对象(实体)和DAO对象,非常的繁琐而且也加大了使用成本。
GreenDao 3.0之后最大的变化就是采用注解的方式通过编译方式生成Java数据对象和DAO对象。
本篇我们就交大家集成最新版本V3.2.2.
1.在project中的gradle添加
// In your root build.gradle file:
buildscript {
repositories {
...省略mavenCentral() // add repository } dependencies { ...省略 classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2' // add plugin }}
2.在moudle的gradle中添加
// In your app projects build.gradle file:
...省略 apply plugin: 'org.greenrobot.greendao' // apply plugin dependencies {
...省略
implementation 'org.greenrobot:greendao:3.2.2' // add library
}
3.配置GreenDao基本参数
4.配置到这里就结束了。下面演示怎么使用。
这里用学生的例子演示增删改查的操作。
1)创建student类
2)build项目,自动生成文件
3)
会自动生成set.get方法
未在gradle中制定目录的话,会在这个目录生成下面三个文件。如下图
4)剩下的就是获取Dao,及具体的操作了。均在mainactivity中实现
贴出源码链接: 点击下载源码