GreenDao数据库的使用方法
来源:互联网 发布:windows日志服务器搭建 编辑:程序博客网 时间:2024/05/21 10:43
Project gradle依赖
buildscript { repositories { jcenter() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:2.3.1' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2'
Module gradle依赖
apply plugin: 'org.greenrobot.greendao'compile 'org.greenrobot:greendao:3.2.2'
greendao { schemaVersion 1 daoPackage 'com.example.zhang20171130.gen' //改成当前工程的包名.gen targetGenDir 'src/main/java' }在Bean类中加入注解
@Entitypublic class Person { @Id private Long id;Build--Make Module 编译一下DbHelper
public class DbHelper { private static volatile DbHelper instance; private final DaoSession daoSession; private final DaoMaster daoMaster; public DbHelper(Context context) { //初始化数据库的一些配置 DaoMaster.DevOpenHelper helper=new DaoMaster.DevOpenHelper(context,"user",null); //获取数据库的操作对象 SQLiteDatabase database = helper.getWritableDatabase(); //获取DaoMaster对象 daoMaster = new DaoMaster(database); //获取DaoSession对象 daoSession =daoMaster.newSession(); } public static DbHelper getInstance(Context context){ if(instance == null){ synchronized (DbHelper.class){ if(null==instance){ instance=new DbHelper(context); } } } return instance; } public PersonDao getPerson(){ return daoSession.getPersonDao(); }}增删改查的方法@OnClick({R.id.zeng, R.id.shan, R.id.gai, R.id.cha})public void onViewClicked(View view) { switch (view.getId()) { case R.id.zeng: Person p=new Person(); p.setId(Long.parseLong(ed1.getText().toString())); p.setName(ed2.getText().toString()); dao.insert(p); break; case R.id.shan: Person p1=new Person(); p1.setId(Long.parseLong(ed1.getText().toString())); p1.setName(ed2.getText().toString()); dao.delete(p1); break; case R.id.gai: Person p2=new Person(Long.parseLong(ed1.getText().toString()),ed2.getText().toString()); dao.update(p2); break; case R.id.cha: persons = dao.loadAll(); adapter = new Adapter(this,persons); lv.setAdapter(adapter); adapter.notifyDataSetChanged(); break; }}
阅读全文
0 0
- GreenDao数据库的使用方法
- GreenDao的使用方法
- GreenDao数据库的使用
- GreenDao数据库的使用
- GreenDao(数据库)的使用
- GreenDao的数据库存储
- GreenDao 使用方法
- Android ORM框架之GreenDao的使用方法
- GreenDao的使用方法和配置方法
- 数据库之greenDAO 的使用
- android的存储GreenDao数据库
- GreenDao数据库框架的使用
- GreenDao数据库的配置流程
- Android--------GreenDao数据库的使用
- Android数据库 GreenDao的使用
- greendao数据库升级(数据库表的迁移)
- GreenDao数据库
- GreenDao数据库
- C语言进阶-第36~37讲:随机读写&二进制文件&文件操作整理
- 【JavaWeb】HTTP status error 500
- log4net使用详解
- web页面_jsp中进行删除跳转
- tomcat在eclipse中打开但8080测试失败
- GreenDao数据库的使用方法
- bootstrap响应式
- 【BLE】CC2541低功耗测试-系统运行篇
- ios端禁止屏幕缩放:
- SQL入门 3 管理数据库对象
- U盘怎样传输大于4G的文件?
- 应用示例:图像文字识别
- [微信小程序]提交表单返回成功后自动清空表单的值
- Git安装配置与GitHub注册及简单使用