GreenDao3使用简介

最近公司项目要做一个搜索的功能,原是通过http请求由服务器来做此项检索功能,这样App使用体验的好坏直接受网络好坏的影响,为了给用户更好的体验,本人想着将该搜索功能本地化,原以为算法组是通过C自己做的搜索引擎,没想到他们是通过ElasticSerarch框架做的。这样将做搜索功能的重担放到了客户端,在没有算法支持的前提下,只能想到的是for循环全匹配字符串来实现,但是for循环在数据量很大的情况下会给程序稳定性带来影响,本人想出的办法是通过检索数据库来完成,这样程序稳定性不受影响,由于很久开发没有用过数据库,所以经常调研,找到了GreenDao数据库框架来完成该功能。以下是GreenDao框架的github连接:https://github.com/greenrobot/greenDAO/,接下来开始真正的数据库开发流程:

一、首先配置greenDao

// In your root build.gradle file:
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
    }
}
 
// In your app projects build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao' // apply plugin
 
dependencies {
    implementation 'org.greenrobot:greendao:3.2.2' // add library
}

注意是在俩build.gradle 文件中完成。

猜你喜欢

转载自blog.csdn.net/zhizhuodewo6/article/details/81386636