【Android】解决GreenDao模糊查询数据为0
问题复现
模糊查询,我们在GreenDao是使用like
我们查询学生名称包含“一”的,代码示例:
public List queryListByMessage(String name){
DaoSession daoSession = ((Application) getApplication()).getDaoSession();
QueryBuilder qb = daoSession.queryBuilder(Student.class);
QueryBuilder studentQueryBuilder = qb.where(StudentDao.Properties.Name.like("一")).orderAsc(StudentDao.Properties.Name);
List studentList = studentQueryBuilder.list();
return list;
}
这样查询出来的数据是0
解决办法
【【Android】解决GreenDao模糊查询数据为0】在like方法中,将字符串前后加上%符号,代码示例:
public List queryListByMessage(String name){
DaoSession daoSession = ((Application) getApplication()).getDaoSession();
QueryBuilder qb = daoSession.queryBuilder(Student.class);
QueryBuilder studentQueryBuilder = qb.where(StudentDao.Properties.Name.like("%"+"一"+"%")).orderAsc(StudentDao.Properties.Name);
List studentList = studentQueryBuilder.list();
return list;
}
推荐阅读
- 宽容谁
- 我要做大厨
- android第三方框架(五)ButterKnife
- 增长黑客的海盗法则
- 画画吗()
- 2019-02-13——今天谈梦想()
- 远去的风筝
- 三十年后的广场舞大爷
- 叙述作文
- 20190302|20190302 复盘翻盘