【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; }

    推荐阅读