当前位置:网站首页>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
边栏推荐
- Necessary for beginners: debug breakpoint debugging skills in idea and common breakpoint skills
- PHP one-time request lifecycle
- Use spiel expressions in custom annotations to dynamically obtain method parameters or execute methods
- The fourth week of summer vacation
- Installation and use of cocoapods
- Wu Enda linear regression of machine learning
- 如何写一篇百万阅读量的文章
- Study notes of the second week of sophomore year
- Self encapsulated database dbutils universal template
- What is the principle of reflection mechanism?
猜你喜欢
随机推荐
数通基础-TCPIP参考模型
服务发现原理分析与源码解读
Okaleido ecological core equity Oka, all in fusion mining mode
输入整数后输入整行字符串的解决方法
Use of selectors
Study notes of the second week of sophomore year
Replay the snake game with C language (II) end
Opencv image processing
C language course design Tetris (Part 2)
如何写一篇百万阅读量的文章
服务发现原理分析与源码解读
Meeting OA project (III) -- my meeting (meeting seating and submission for approval)
Solution of inputting whole line string after inputting integer
The problem of incomplete or partial display of the last recyclerview is solved
The use of MySQL in nodejs
Basic usage of protobuf
Leetcode 504. Hex number
Keeping alive to realize MySQL automatic failover
数通基础-Telnet远程管理设备
30分钟彻底弄懂 synchronized 锁升级过程