当前位置:网站首页>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
边栏推荐
- Data communication foundation - layer 2 switching principle
- Principle analysis and source code interpretation of service discovery
- Encapsulation of tabbarcontroller
- 点赞,《新程序员》电子书限时免费领啦!
- The use of MySQL in nodejs
- Redis realizes distributed lock and gets a watchdog
- Study notes of the fifth week of sophomore year
- Keeping alive to realize MySQL automatic failover
- Necessary for beginners: debug breakpoint debugging skills in idea and common breakpoint skills
- 简单化构造函数的继承方法(一)- 组合继承
猜你喜欢

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

El table implements adding / deleting rows, and a parameter changes accordingly

Learning about tensorflow (I)

Applet record

Leetcode 504. 七进制数

新建福厦铁路全线贯通 这将给福建沿海带来什么?

Beginner of flask framework-04-flask blueprint and code separation

Data communication foundation telnet remote management equipment

Distributed network communication framework: how to publish local services into RPC services
![[fluorescent character effect]](/img/05/4f4c24c787881e073919b63a6864cf.jpg)
[fluorescent character effect]
随机推荐
Data communication foundation - layer 2 switching principle
The fourth week of summer vacation
面试第二家公司的面试题及答案(二)
[fluorescent character effect]
Production of a-modal drag function in antui
服务器内存故障预测居然可以这样做!
Mysql5.7.25 master-slave replication (one-way)
数通基础-网络基础知识
SQL Server 2008 R2 installation problems
Employee information management system based on Web
Cause: couldn‘t make a guess for 解决方法
时间序列异常检测
分布式网络通信框架:本地服务怎么发布成RPC服务
Reproduce the snake game in C language (I) build pages and construct snakes
C language course design Tetris (Part 1)
Principle analysis and source code interpretation of service discovery
What is the principle of reflection mechanism?
Vs Code configures go locale and successfully installs go related plug-ins in vscode problem: Tools failed to install
Network related journals and conferences in CS
Some descriptions of DS V2 push down in spark