GreenDao查询,有时会查不到数据,解决方法。

greendao 实体类的id 需要设置为Long

例如根据ID查询数据

我这ID是long类型,

执行for循环第一次能查到,

第二次就查不到。

根据多次实验,把ID转成Long类型再执行查询就没有问题了,



@Override
public void updateIsSave(List recordIdList) {
    QueryBuilder queryBuilder = MyApplication.flightRecordDao.queryBuilder();
    LM_FlightRecordDao flightRecordDao = MyApplication.flightRecordDao;
    for (int i = 0; i < recordIdList.size() - 1; i++) {
        long currentId=recordIdList.get(i);
         List list = queryBuilder.where(LM_FlightRecordDao.Properties.Id.eq(currentId)).list();
        if (list != null && list.size() > 0) {
            LM_FlightRecord flightRecord = list.get(0);
            flightRecord.setIsSave(1);
            flightRecordDao.insertOrReplace(flightRecord);
        }

    }

}

你可能感兴趣的:(Android)