GreenDao 分页条件查询排序

分页加载20条数据,getTwentyRec(int offset)中控制页数offset++即可

     DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(context, "arnold.db");
     DaoMaster daoMaster = new DaoMaster(devOpenHelper.getWritableDb());
     AbstractDaoSession  daoSession = daoMaster.newSession();

     List listMsg = daoSession.queryBuilder(UserEntity.class).offset(offset * 20).limit(20).list();

 

 (1)orderAsc:升序排序 
(2)orderDesc: 降序排序 
(3)eq():== 
(4)noteq():!= 
(5)gt(): > 
(6)t():< 
(7)ge:>= 
(8)le:<= 
(9)like():包含 
(10)between:俩者之间 
(11)in:在某个值内 
(12)notIn:不在某个值内
userDao.queryBuilder()
  .where(Properties.FirstName.eq("Joe"))
  .orderAsc(Properties.LastName)
  .list();

orderDesc 排序后截取分页加载数据 


   /**
     * 分页条件查询实体集合
     *
     * @param entityClass
     * @param offset
     * @param limit
     * @param where
     * @param selectionArgs
     * @param 
     *
     * @return
     */
    public  List queryPage(Class entityClass, int offset, int limit, String where,
            Property properties, Object... selectionArgs) {
        AbstractDao dao = (AbstractDao) daoSession.getDao(entityClass);
        QueryBuilder builder = dao.queryBuilder()
                .orderDesc(properties)
                .where(
                        new WhereCondition.StringCondition(where, selectionArgs))
                .offset(offset * limit)
                .limit(limit);
        return builder.list();
    }

 

你可能感兴趣的:(数据库)