GreenDao模版
来源:互联网 发布:淘宝网网页显示不正常 编辑:程序博客网 时间:2024/05/22 15:36
工程build.gradle中:
buildscript { repositories { jcenter()mavenCentral() //加的东西}
dependencies { classpath 'com.android.tools.build:gradle:2.3.3' classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2' //加的东西}Appbuild.gradle中:
头部: apply plugin: 'org.greenrobot.greendao'
依赖: compile 'org.greenrobot:greendao:3.2.2'
greendao { schemaVersion 1 daoPackage 'com.example.greendaolianxi.gen' //加的---包名.gen targetGenDir 'src/main/java' }同步,
完成之后,新建Bean类
Long类型的属性id
@Entity //类的头部加入此注解public class Bean {
@Id //ID属性上加入private Long wid;
最后点击AndroidStudio的头部的标题栏的Build的第二个Make Modle '*****'
出来gen文件夹,就完成了
创建数据库:
public class DBUtils { private static volatile DBUtils instance; private final BeanDao dao; //gen中的...Dao类 private DBUtils(Context context) { DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, "bean.db", null); SQLiteDatabase database = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(database); DaoSession daoSession = daoMaster.newSession(); dao = daoSession.getBeanDao(); //gen中的...Dao类的方法 } public static DBUtils getInstance(Context context){ if (instance == null) { synchronized (DBUtils.class) { if (null == instance) { instance = new DBUtils(context); } } } return instance; } public BeanDao getDao(){ return dao; //返回 }}
获取数据库:注意接收的数据库返回类型是gen里的Dao类
BeanDao dao;
dao = DBUtils.getInstance(this).getDao();
阅读全文
0 0
- GreenDao模版
- greenDao
- greenDAO
- greenDAO
- greenDAO
- GreenDao
- GreenDAO
- Greendao
- greenDAO
- GreenDao
- GreenDao
- GreenDao
- GreenDAO
- GreenDAO
- GreenDao
- GreenDao
- greenDAO
- GreenDAO
- POJ:3608 Bridge Across Islands 旋转卡壳
- 016 统计量总结、车比雪夫不等式
- 【07-Redis从文件中批量插入数据】
- 基于USDT的比特币新交易
- curator监听zookeeper目录(TreeNode)
- GreenDao模版
- python-pptx对已有ppt进行修改
- 经典美文诵读1-【What I Have Lived For(我为何而活) Bertrand Russell(伯兰特.罗素) 】
- 循环神经网络(RNN)之LSTM(Long Short Term Memory networks)
- 欢迎使用CSDN-markdown编辑器
- Xcode9学习笔记77
- Linux下安装MongoDB
- Java程序员从阿里、京东、美团面试回来,这些面试题你会吗?
- 《七点三刻》022期 明年节假日公布/“悟空”看到暗物质/麻辣烫有了英文名……