GreenDao集成教程(一) GD基本集成

作者: 冷寒 | 来源:发表于2017-11-27 18:07 被阅读48次

    GreenDao引用

    Project-->Gradle

    buildscript {
        
        repositories {
            ...
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.0.1'
            classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2' // 添加插件 更好支持GreenDao
            ...
        }
    }
    
    allprojects {
        repositories {
            ...
        }
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    

    APP-->Gradle

    apply plugin: 'com.android.application'
    apply plugin: 'org.greenrobot.greendao' // 添加应用依赖插件
    android {
        compileSdkVersion 26
        defaultConfig {
            ...
        }
        buildTypes {
            ...
        }
    
        // 配置GreenDao基本参数
        greendao {
            schemaVersion 1 //当前数据库版本
        }
    }
    
    dependencies {
        ...
        //log
        compile 'com.orhanobut:logger:1.15'
        //数据库调试
        debugCompile 'com.amitshekhar.android:debug-db:1.0.0'
        //GreenDao
        compile 'org.greenrobot:greendao:3.2.2' // 添加GreenDao库
    }
    

    定义实体Entity

    @Entity
    public class Member {
        @Id(autoincrement = true) // id自增长
        private Long memId; // 学院id
    
        private String memName; // 学员姓名
    
        private int memSex; // 学员性别
    }
    

    编译自动生成GreenDAO相关工具类以及SQL等

    DEMO入口

    相关文章

      网友评论

        本文标题:GreenDao集成教程(一) GD基本集成

        本文链接:https://www.haomeiwen.com/subject/rfwdbxtx.html