DBFlow框架的学习笔记之入门
2024-10-08 21:08:36
什么是DBFlow?
dbflow是一款android高性的ORM数据库.可以使用在进行项目中有关数据库的操作。github下载源码
1、环境配置
- 先导入 apt plugin库到你的classpath,以启用AnnotationProcessing(注解处理器):在工程的根目录下build.gradle代码如下:
12345678910111213141516buildscript {repositories {jcenter()}dependencies {classpath 'com.android.tools.build:gradle:2.2.2'classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'}}allprojects {repositories {jcenter()maven { url "https://www.jitpack.io" }}}
添加 classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.8’
和 maven { url “https://www.jitpack.io“ }
添加库到项目级别的build.gradle文件中
123456789101112131415161718192021222324252627282930313233343536apply plugin: 'com.android.application'apply plugin: 'com.neenbedankt.android-apt'def dbflow_version = "3.0.0-beta4"android {compileSdkVersion 25buildToolsVersion "25.0.0"defaultConfig {applicationId "com.soildog.testdbflow"minSdkVersion 21targetSdkVersion 25versionCode 1versionName "1.0"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}buildTypes {release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}}}dependencies {compile fileTree(include: ['*.jar'], dir: 'libs')androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {exclude group: 'com.android.support', module: 'support-annotations'})testCompile 'junit:junit:4.12'//supportcompile 'com.android.support:appcompat-v7:25.0.1'compile 'com.android.support:design:25.0.1'// dbflowapt "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}"compile "com.github.Raizlabs.DBFlow:dbflow-core:${dbflow_version}"compile "com.github.Raizlabs.DBFlow:dbflow:${dbflow_version}"}
2.初始化DBFlow
|
|
记得添加到AndroidManifest.xml中,name = “App”
3、创建数据库:
|
|
4、创建数据库表:
|
|
(1)对类添加@Table注解
(2) 声明所连接的数据库类,这里是DBFlowDatabase。
(3)定义至少一个主键。
(4)这个类和这个类中数据库相关列的修饰符必须是包内私有或者public,这样生成的_Adapter类能够访问到它。
创建完成后,需要编译一下,点击编译按钮,或者Build->Make Project即可,它会自动生成一些数据库文件,也会提示你创建是否有误!
如果编译通过会生成一些类,位置:TestDBFLowappbuildgeneratedsourceaptdebugcomsoildogtestdbflowentity
如:Student_Table(在下文中很重要)
5、创建一个管理类用于对数据的增删该查
|
|
ps:Student_Table是如何出现的那?->>是自动编译生成的。
6、最后就是写一个测试类去测试一下,这里就不多说了。。。
参考:
android篇 未完待续。。。
最新文章
- Android 内存管理 &;Memory Leak &; OOM 分析
- 解读SDN的东西、南北向接口
- 2015 MVP OpenDay 及 Community Camp 演讲PPT分享
- 使用 CSS3 伪元素实现立体的照片堆叠效
- Intent学习笔记
- hdu 2053 Switch Game 水题一枚,鉴定完毕
- 丢掉 WinPE,使用 DISKPART 来分区吧
- linux下查看磁盘空间
- 把WinXP装进内存 性能飚升秒杀固态硬盘
- ios runtime部分事例方法说明
- 201521123052 《Java程序设计》 第14周学习总结
- Troubleshooting tips for using Java on Windows 8
- 第三次Java作
- udp套接字及利用socketserver模块实现并发以及并发编程
- C++学习札记(1)
- myBatis插件(plugins)
- C# RichTextBox的用法
- sqler sql 转rest api 的docker image
- mongodb命令(1)
- C#中简单的文件操作实例