zoukankan      html  css  js  c++  java
  • greendao3.2.0使用

    源代码地址 https://github.com/greenrobot/greenDAO

    buildscript {
    repositories {
    jcenter()
    mavenCentral()
    }
    dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'
    classpath 'org.greenrobot:greendao-gradle-plugin:3.2.1'
    }
    }
    apply plugin: 'com.android.application'
    apply plugin: 'org.greenrobot.greendao'
     
    greendao{
    schemaVersion 1
    daoPackage 'com.xxx.video.db' //生成DaoMaster、DaoSession、Dao路径
    targetGenDir 'src/main/java/' //生成DaoMaster、DaoSession、Dao目录
    }
    dependencies { compile 'org.greenrobot:greendao:3.2.0' }

    @Entity
    public class User {
    @Id
    private Long id;

    private String name;

    @Transient
    private int tempUsageCount;  
    }

    点击Build-->Make Project 

    在com.xxx.video.db下会生成  DaoMaster DaoSession 和上面新建User类的DAO UserDao类

    Application初始化


    private DaoMaster mDaoMaster;
    private DaoSession mDaoSession;
    DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(AppApplication.getContext(), "video-db", null);//此处为自己需要处理的表
    mDaoMaster = new DaoMaster(devOpenHelper.getWritableDatabase());
    mDaoSession = mDaoMaster.newSession();

    public static DaoSession getDaoSession() {
        return mDaoSession;
    }

    调用方法
    AppApplication.getDaoSession().getUserDao();
    根据条件查询
    User mUser=AppApplication.getDaoSession().getUserDao().queryBuilder().where(UserDao.Properties.name.eq("yu")).unique(); 查询name等于yu的用户

    List<User> mList=AppApplication.getDaoSession().getUserDao().queryBuilder().where(UserDao.Properties.name.eq("yu")).list(); 查询name等于yu的用户列表

     


     
  • 相关阅读:
    Ubuntu12.04配置永久静态ip地址
    linux shell 命令获取字符串/文件的MD5值
    设置VMware中Kali 共享文件夹
    tomcat的一些优化及报错
    用Toad for Oracle创建数据库表空间和用户
    linux远程Windows服务器
    linux查询及添加用户
    AJAX
    Cookie和Session
    Django-中间件
  • 原文地址:https://www.cnblogs.com/freexiaoyu/p/6278042.html
Copyright © 2011-2022 走看看