MongoTemplate的字段模糊查询,相当like
解决方法:
Criteria where = new Criteria();
where.and("title").regex(".*?\\" +title+ ".*");
Query query=new Query(where);
long count = template.count(query, Survey.class);
Pageable pageable = new PageRequest(0,10);
List<Survey> pageList = template.find(query.with(pageable).with(new Sort(new Sort.Order(Sort.Direction.DESC,"排序的字段名"))), Survey.class);
其中Survey是mongodb表的映射类
@Document(collection = "survey")
public class Survey {
}