码上敲享录 > mongoDB常见问题解答 > MongoTemplate的字段模糊查询,相当like

MongoTemplate的字段模糊查询,相当like

上一章章节目录下一章 2020-02-20已有3886人阅读 评论(0)

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 {

}


向大家推荐《Activiti工作流实战教程》:https://xiaozhuanlan.com/activiti
0

有建议,请留言!

  • *您的姓名:

  • *所在城市:

  • *您的联系电话:

    *您的QQ:

  • 咨询问题:

  • 提 交