美文网首页Android开发经验谈程序员
2019-03-14 数据库:Greendao 集成

2019-03-14 数据库:Greendao 集成

作者: 喜欢萌妹子的少年 | 来源:发表于2019-03-14 17:17 被阅读6次

前言

DreenDAO is a light & fast ORM for Android that maps objects to SQLite databases. Being highly optimized for Android, greenDAO offers great performance and consumes minimal memory.

DreenDAO是一款轻巧快捷的Android版ORM,可将对象映射到SQLite数据库。 greenDAO针对Android进行了高度优化,性能卓越,占用内存极少。

GreenDao 3.2.2 配置

  1. Add the following Gradle configuration to your Android project. In your root build.gradle file:

在工程根目录 build.gradle 文件中 添加配置。

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

在 App 模块 build.gradle 文件中 添加配置

apply plugin: 'org.greenrobot.greendao'

 greendao {
    schemaVersion 1
    daoPackage '包名.gen'
    targetGenDir 'src/main/java'
}
  ....
dependencies {
      ....
      implementation 'org.greenrobot:greendao:3.2.2'
}

  1. 创建实体对象类
不需要自己写get和set方法 , 在生成表的时候会自动生成

不要忘了在类名上标记@Entity注解

不要忘了在类名上标记@Entity注解

不要忘了在类名上标记@Entity注解


 @Entity:告诉GreenDao该对象为实体,只有被@Entity注释的Bean类才能 
 被dao类操作
 @Id:对象的Id,使用Long类型作为EntityId,否则会报错。(autoincrement 
 = true)表示主键会自增,如果false就会使用旧值
 @Property:可以自定义字段名,注意外键不能使用该属性
 @NotNull:属性不能为空
 @Transient:使用该注释的属性不会被存入数据库的字段中
 @Unique:该属性值必须在数据库中是唯一值
 @Generated:编译后自动生成的构造函数、方法等的注释,提示构造函 
 数、方法等不能被修改

写好实体类之后重新编译 (command+F9)(Make project )

相关文章

  • 2019-03-14 数据库:Greendao 集成

    前言 DreenDAO is a light & fast ORM for Android that maps o...

  • greenDAO封装

    EasygreenDAO 基于greenDAO的上层调用封装。 greenDAO的集成 greenDAO的集成和说...

  • GreenDao数据库集成

    前言 最近的项目需要使用到数据库,本来想用Sqlite数据来做的,但是听同事说使用Greendao数据库是真的好用...

  • GreenDao简单使用和数据库升级

    一 GreenDao的配置 学习/参考地址:GreenDao3.0数据库的简单使用GreenDAO数据库升级 1、...

  • GreenDao 使用

    目录结构: 关于GreenDao 集成步骤 2.1 下载配置 [GREENDAO GENERATOR] 2.2 定...

  • Android数据库选型

    一、GreenDao和其他数据库对比 1、GreenDao官方提供的和GreenDao ,OrmLite,Acti...

  • Android平台下

    greenDao的介绍 greenDao是Android数据库ORM(object/relational mapp...

  • GreenDAO 3.0学习

    Android数据库框架GreenDao的简单使用 1. GreenDao介绍: greenDAO是一个对象关系映...

  • GreenDao集成

    1.项目gradle dependencies下添加 classpath'org.greenrobot:green...

  • GreenDao3.2.2集成和基本使用

    GreenDao3.2.2集成和基本使用 官方git网址:greenrobot/greenDAO 优点:一个精简的...

网友评论

    本文标题:2019-03-14 数据库:Greendao 集成

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