MongoTemplate根据数组中的元素查找
解决方法:
假如designer表中有一个字段是roles,roles是字符串数组,值为[admin,admin1,admin2],现在要查找designer表中roles包含admin的记录
Criteria where = new Criteria();
where.and("roles").is(role);
Query query=new Query(where);
long count = template.count(query, Designer.class);
Pageable pageable = new PageRequest(page==null?0:page,pageSize==null?10:pageSize);
List<Designer> pageList = template.find(query.with(pageable), Designer.class);
如果roles是json数组,where.and("roles.键名").is(role);