关于greenDao的配置

版权声明:欢迎大家关注我的博客,更多文章请移步新的地址:http://student9128.top https://blog.csdn.net/student9128/article/details/79178917

greenDao是一个开源的数据库解决方案,至于其优势劣势不啰嗦,关键是能用,好用就行。
这里简单记录下其配置方法
greenDao的github地址https://github.com/greenrobot/greenDAO
这里同样像其他文章写得那样贴图。贴图比较明了。

在Gradle里配置如下代码

// In your root build.gradle file:
buildscript {
    repositories {
        jcenter()
        mavenCentral() // add repository
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2' // add plugin
    }
}

// In your app projects build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao' // apply plugin

dependencies {
    compile 'org.greenrobot:greendao:3.2.2' // add library
}

具体配置看贴图

Module Gradle



Project Gradle

gradle里面配置完了以后,新建一个entity里(相当于bean),设置表格中所需要的属性

例如:

@Entity
public class DataEntity {
    @Id
    private Long id;
    private String name;
    private String age;
}

id 就是数据库表格中的id,类型为Long
这些写完就可以直接Make Project了
这里写图片描述

然后会自动生成三个类,刚才所写的类也会变化。如下:红框里的类是生成的,代码变化也如下:
这里写图片描述

@Entity
public class DataEntity {
    @Id
    private Long id;
    private String name;
    private String age;
    @Generated(hash = 1668938553)
    public DataEntity(Long id, String name, String age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }
    @Generated(hash = 1892108943)
    public DataEntity() {
    }
    public Long getId() {
        return this.id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getName() {
        return this.name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getAge() {
        return this.age;
    }
    public void setAge(String age) {
        this.age = age;
    }

}

至此配置就全部完成了。
具体使用请参考SQLitedatabase之GreenDao进行CRUD
这里我只记录了一下简单的CRUD,具体怎么使用还要根据自己的情况。

猜你喜欢

转载自blog.csdn.net/student9128/article/details/79178917