#####android 原生提供的API带来的不方便的地方:

  • 要手动拼装sql
  • 要自己写操作数据库的常规代码
  • 不能自动把数据库中的数据映射成对象
  • 没有实现级联查询

#####什么是GreenDao:

GreenDao是一个高效的数据库访问ORM框架,节省了自己编写SQL的时间,快速的增删查改等操作。
#####什么是ORM:
对象关系映射,,是一种程序技术,用于实现面向对象编程语言里不同类型系统的数据之间的转换
#####GreenDao优点:

  • 让业务代码访问对象,而不是数据库源
  • 隐藏了面向对象的逻辑SQL查询详情
  • 无需处理数据库实现
  • 最高性能(可能是Android上最快的ORM); 我们的基准也是开源的
  • 易于使用的强大API,涵盖关系和连接
  • 最小的内存消耗
  • 小库大小(<100KB)以保持较低的构建时间并避免65k方法限制
  • 数据库加密:greenDAO支持SQLCipher,以确保用户的数据安全
  • 强大的社区:超过5000个GitHub Starts表明有一个强大而活跃的社区

#####集成
GreenDao 3.0采用注解的方式来定义实体类,通过gradle插件生成相应的代码。您可以使用greenDAO Gradle插件,无需任何其他配置,但至少要设置schema的版本等;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// In your root build.gradle file: 项目的build.gradle中
buildscript {
repositories {
jcenter()
mavenCentral() // add repository
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2' // add plugin 这里添加plugin
}
}

// In your app projects build.gradle file: 在app的build.gradle中
apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao' // apply plugin 顶部添加

dependencies {
implementation 'org.greenrobot:greendao:3.2.2' // add library 引入包
}
//无需混淆