当前位置:网站首页>Use of Android grendao database
Use of Android grendao database
2022-07-26 10:16:00 【FrancisBingo】
Integration mode
1. stay app In the catalog build.gralde Integrate
apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao'
dependencies {
// database greenDao
implementation "org.greenrobot:greendao:$greendaoVersion"
}
greendao {
schemaVersion 1 // Database version number
daoPackage 'ai.xxx.xxx.greenDao.db'
// Set up DaoMaster、DaoSession、Dao Package name
targetGenDir 'src/main/java'// Set up DaoMaster、DaoSession、Dao Catalog , Please note that , The path here is / Do not use .
generateTests false // Set to true To automatically generate unit tests .
targetGenDirTests 'src/main/java' // The basic directory of the generated unit tests should be stored . The default is src / androidTest / java.
}2. stay project In the catalog build.gradle Integrate
classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2'
3. Database creation
Can be in Application Create
@Override
public void onCreate() {
super.onCreate();
initDatabase();
}
private void initDatabase() {
// Create database gmtech.db"
DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "mydb.db", null);
// Get writable database
SQLiteDatabase db = helper.getWritableDatabase();
// Get database objects
DaoMaster daoMaster = new DaoMaster(db);
// obtain Dao Object manager
daoSession = daoMaster.newSession();
}
public static DaoSession getDaoSession() {
return daoSession;
}4. Creating a data model
Create a self defined data model and then @Entity modification
@Entity
public class DeviceModel {
public Long address_id;
@Property
public Long room_id;
@Property
public String region_name;
@Property
public String region_type;
}Execute after creating the model build Under the Make Project The corresponding dao file
5. Data manipulation
Generate dao File can be passed dao Object to perform database related operations
边栏推荐
- C language course design Tetris (Part 1)
- I finished watching this video on my knees at station B
- AirTest
- Employee information management system based on Web
- 数据库的复习--1.概述
- C language course design Tetris (Part 2)
- 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
- 时间序列异常检测
- In Net 6.0
- Learning about tensorflow (II)
猜你喜欢

【有奖提问】向图灵奖得主、贝叶斯网络之父 Judea Pearl 提问啦

Keeping alive to realize MySQL automatic failover

Production of a-modal drag function in antui
![Azkaban [basic knowledge 01] core concepts + features +web interface + Architecture +job type (you can get started with Azkaban workflow scheduling system in one article)](/img/f9/c86ccbb0967894d370498c3a9630eb.png)
Azkaban [basic knowledge 01] core concepts + features +web interface + Architecture +job type (you can get started with Azkaban workflow scheduling system in one article)

服务器内存故障预测居然可以这样做!

Leetcode 504. 七进制数

Mqtt x cli officially released: powerful and easy-to-use mqtt 5.0 command line tool

数通基础-Telnet远程管理设备

【Halcon视觉】形态学腐蚀

INSTALL_FAILED_SHARED_USER_INCOMPATIBLE错误解决方式
随机推荐
In Net 6.0
[fluorescent character effect]
Flask框架初学-03-模板
Study notes of the first week of sophomore year
IEEE conference upload font problem
Okaleido生态核心权益OKA,尽在聚变Mining模式
Explain automatic packing and unpacking?
详细解析js中的混合方式构造对象(构造加属性,原型加方法)
[award-winning question] ask Judea pearl, the Turing prize winner and the father of Bayesian networks
AirTest
Interview shock 68: why does TCP need three handshakes?
Why does new public chain Aptos meet market expectations?
Using undertow, Nacos offline logout delay after service stop
Leetcode 504. 七进制数
PHP one-time request lifecycle
Learning about tensor (III)
Yarn 'TSC' is not an internal or external command, nor is it a runnable program or batch file. The problem that the command cannot be found after installing the global package
INSTALL_ FAILED_ SHARED_ USER_ Incompatible error resolution
Uniapp error 7 < Map >: marker ID should be a number
What will the new Fuzhou Xiamen railway bring to Fujian coastal areas?