Android GreenDAO(一)

GreenDao是一个高效的数据库访问ORM框架,节省了自己编写SQL的时间,快速的增删查改等操作。

Github GreenDAO

配置GreenDao

添加在工程的build.gradle

// In your root build.gradle file:
buildscript {
    dependencies {

        classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2' // add plugin
    }
}

 

添加到module的build.gradle文件中

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


android {

    greendao {
        schemaVersion 1  //版本
        // 一般为app包名+生成文件的文件夹名
        daoPackage 'com.example.administrator.mvp.greendao.gen' 
        targetGenDir 'src/main/java' //生成文件路径
    }
}
 

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

创建实体类

@Entity
public class FavorDb {
    @Id
    private Long id;
    @NotNull
    private String title;
    private long update_time;
    private String chapter_name;
    private long chapter_id;
    private boolean isUnRead;
}

创建完成实体类之后点击Build–>MarkProject,会自动在配置的路径下生成DaoMaster、DaoSession、以及UserInfoDao文件(如果拥有多个实体类,则会生成多个实体类Dao文件),并且,刚才编写的实体类文件UserInfo会自动生成get、set方法跟无参构造以及完整参数的构造方法 

package com.example.administrator.mvp.model.db;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.NotNull;
import org.greenrobot.greendao.annotation.Generated;

@Entity
public class FavorDb {
    @Id
    private Long id;
    @NotNull
    private String title;
    private long update_time;
    private String chapter_name;
    private long chapter_id;
    private boolean isUnRead;
    @Generated(hash = 172177374)
    public FavorDb(Long id, @NotNull String title, long update_time,
            String chapter_name, long chapter_id, boolean isUnRead) {
        this.id = id;
        this.title = title;
        this.update_time = update_time;
        this.chapter_name = chapter_name;
        this.chapter_id = chapter_id;
        this.isUnRead = isUnRead;
    }
    @Generated(hash = 1955454265)
    public FavorDb() {
    }
    public Long getId() {
        return this.id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getTitle() {
        return this.title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public long getUpdate_time() {
        return this.update_time;
    }
    public void setUpdate_time(long update_time) {
        this.update_time = update_time;
    }
    public String getChapter_name() {
        return this.chapter_name;
    }
    public void setChapter_name(String chapter_name) {
        this.chapter_name = chapter_name;
    }
    public long getChapter_id() {
        return this.chapter_id;
    }
    public void setChapter_id(long chapter_id) {
        this.chapter_id = chapter_id;
    }
    public boolean getIsUnRead() {
        return this.isUnRead;
    }
    public void setIsUnRead(boolean isUnRead) {
        this.isUnRead = isUnRead;
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值