当前位置:网站首页>Android greendao数据库的使用
Android greendao数据库的使用
2022-07-26 10:14:00 【FrancisBingo】
集成方式
1.在app目录下的build.gralde集成
apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao'
dependencies {
//数据库 greenDao
implementation "org.greenrobot:greendao:$greendaoVersion"
}
greendao {
schemaVersion 1 //数据库版本号
daoPackage 'ai.xxx.xxx.greenDao.db'
// 设置DaoMaster、DaoSession、Dao 包名
targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录,请注意,这里路径用/不要用.
generateTests false //设置为true以自动生成单元测试。
targetGenDirTests 'src/main/java' //应存储生成的单元测试的基本目录。默认为 src / androidTest / java。
}2.在project目录下的build.gradle集成
classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2'
3.数据库的创建
可以在Application下创建
@Override
public void onCreate() {
super.onCreate();
initDatabase();
}
private void initDatabase() {
//创建数据库gmtech.db"
DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "mydb.db", null);
//获取可写数据库
SQLiteDatabase db = helper.getWritableDatabase();
//获取数据库对象
DaoMaster daoMaster = new DaoMaster(db);
//获取Dao对象管理者
daoSession = daoMaster.newSession();
}
public static DaoSession getDaoSession() {
return daoSession;
}4.创建数据模型
创建一个我自定义的数据模型再用@Entity修饰
@Entity
public class DeviceModel {
public Long address_id;
@Property
public Long room_id;
@Property
public String region_name;
@Property
public String region_type;
}创建好模型后再执行build下的Make Project 即可自动生成对应的dao文件
5.数据操作
生成dao文件后即可通过dao对象进行数据库相关操作
边栏推荐
- Study notes of the second week of sophomore year
- Installation and use of cocoapods
- Draw arrows with openlayer
- Unstoppable, pure domestic PCs have been in place, and the monopoly of the U.S. software and hardware system has been officially broken
- Study on the basis of opencv
- 论文笔记(SESSION-BASED RECOMMENDATIONS WITHRECURRENT NEURAL NETWORKS)
- Interview shock 68: why does TCP need three handshakes?
- Apple dominates, Samsung revives, and domestic mobile phones fail in the high-end market
- In Net 6.0
- Study notes of the third week of sophomore year
猜你喜欢

SQL优化的魅力!从 30248s 到 0.001s
![Uniapp common error [wxml file compilation error]./pages/home/home Wxml and using MySQL front provided by phpstudy to establish an independent MySQL database and a detailed tutorial for independent da](/img/21/5dceab9815b503f0b62d26a430d7eb.png)
Uniapp common error [wxml file compilation error]./pages/home/home Wxml and using MySQL front provided by phpstudy to establish an independent MySQL database and a detailed tutorial for independent da

如何写一篇百万阅读量的文章

MySQL 5.7.25 source code installation record

On the compilation of student management system of C language course (simple version)

2021 windows penetration of "Cyberspace Security" B module of Shandong secondary vocational group (analysis)

30分钟彻底弄懂 synchronized 锁升级过程

Map key not configured and uniapp routing configuration and jump are reported by the uniapp < map >< /map > component

服务发现原理分析与源码解读

Session based recommendations with recurrent neural networks
随机推荐
Nodejs service background execution (forever)
Interview shock 68: why does TCP need three handshakes?
【有奖提问】向图灵奖得主、贝叶斯网络之父 Judea Pearl 提问啦
数据库的复习--3.SQL语言
Jpg to EPS
Mysql5.7.25 master-slave replication (one-way)
JS table auto cycle scrolling, mouse move in pause
Spolicy request case
Learning about opencv (4)
SQL Server 2008 R2 installation problems
Common errors when starting projects in uniapp ---appid
Error in render: "typeerror: cannot read properties of undefined (reading 'length')" --- error when calling interface
Map key not configured and uniapp routing configuration and jump are reported by the uniapp < map >< /map > component
Interpretation of the standard of software programming level examination for teenagers_ second level
Session based recommendations with recurrent neural networks
IEEE conference upload font problem
Interview shock 68: why does TCP need three handshakes?
Rowselection emptying in a-table
Keeping alive to realize MySQL automatic failover
[datawhale] [machine learning] Diabetes genetic risk detection challenge