Android GreenDao 条件查询问题

发布于 2022-09-04 13:54:05 字数 4082 浏览 12 评论 0

使用GreenDao保存了全国城市的属性(名字,代码,省份等等),保存可以成功,无条件查询全部数据时可以成功:

private List<CityInfo> queryCitiesInfo(){
        List<CityInfo> cityInfos = mCityQUery.list();
        for (int i = 0; i < cityInfos.size(); i++) {
            Log.d(TAG,"所有的城市CountryEn"+cityInfos.get(i).getCountryEn());
        }
        return cityInfos;
    }

但是使用条件查询,时数据为0,不知道哪里出错了,对了下属性,没知道原因:

//这个方法查询的数据为0
private void queryCitiesByLeader(){
        mCityInfoDao = nDaoSession.getCityInfoDao();
        mCityQUery = mCityInfoDao.queryBuilder().orderAsc(CityInfoDao.Properties.Id).build();
        List<CityInfo> cityInfos = mCityInfoDao.queryBuilder().where(CityInfoDao.Properties.CountryEn.eq("China")).orderAsc(CityInfoDao.Properties.Id).list();
        for (int i = 0; i < cityInfos.size(); i++) {
            Log.d(TAG,"条件查询城市名称" + cityInfos.get(i).getCityEn());
        }
    }
@Entity
public class CityInfo {
    
    @Id
    private Long id;
    private String cityEn;
    private String cityZh;
    private String countryCode;
    private String countryEn;
    private String countryZh;
    private String provinceEn;
    private String provinceZh;
    private String leaderEn;
    private String leaderZh;
    private String lat;
    private String lon;
    @Generated(hash = 69148619)
    public CityInfo(Long id, String cityEn, String cityZh, String countryCode,
            String countryEn, String countryZh, String provinceEn,
            String provinceZh, String leaderEn, String leaderZh, String lat,
            String lon) {
        this.id = id;
        this.cityEn = cityEn;
        this.cityZh = cityZh;
        this.countryCode = countryCode;
        this.countryEn = countryEn;
        this.countryZh = countryZh;
        this.provinceEn = provinceEn;
        this.provinceZh = provinceZh;
        this.leaderEn = leaderEn;
        this.leaderZh = leaderZh;
        this.lat = lat;
        this.lon = lon;
    }
    @Generated(hash = 300452937)
    public CityInfo() {
    }
    public Long getId() {
        return this.id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getCityEn() {
        return this.cityEn;
    }
    public void setCityEn(String cityEn) {
        this.cityEn = cityEn;
    }
    public String getCityZh() {
        return this.cityZh;
    }
    public void setCityZh(String cityZh) {
        this.cityZh = cityZh;
    }
    public String getCountryCode() {
        return this.countryCode;
    }
    public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    }
    public String getCountryEn() {
        return this.countryEn;
    }
    public void setCountryEn(String countryEn) {
        this.countryEn = countryEn;
    }
    public String getCountryZh() {
        return this.countryZh;
    }
    public void setCountryZh(String countryZh) {
        this.countryZh = countryZh;
    }
    public String getProvinceEn() {
        return this.provinceEn;
    }
    public void setProvinceEn(String provinceEn) {
        this.provinceEn = provinceEn;
    }
    public String getProvinceZh() {
        return this.provinceZh;
    }
    public void setProvinceZh(String provinceZh) {
        this.provinceZh = provinceZh;
    }
    public String getLeaderEn() {
        return this.leaderEn;
    }
    public void setLeaderEn(String leaderEn) {
        this.leaderEn = leaderEn;
    }
    public String getLeaderZh() {
        return this.leaderZh;
    }
    public void setLeaderZh(String leaderZh) {
        this.leaderZh = leaderZh;
    }
    public String getLat() {
        return this.lat;
    }
    public void setLat(String lat) {
        this.lat = lat;
    }
    public String getLon() {
        return this.lon;
    }
    public void setLon(String lon) {
        this.lon = lon;
    }
}

下面是部分日志,打印出CountryEn:
图片描述

第一次用GreenDao, 找了很久没发现问题,望解答,感谢。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

維他命╮ 2022-09-11 13:54:05

没有看到你的表结构及数据字段结构组成,没法准确判断你的问题了,我对你的“China”条件存疑,你检查你的条件是否正确。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文