-
Criteria criteria = new Criteria(); if (StringUtils.isNotBlank(keywords)) { criteria.orOperator(Criteria.where("name").regex(keywords, "i"), Criteria.where("comment").regex(keywords, "i"), Criteria.where("referName").regex(keywords, "i") ); } Query query = new Query(criteria).with(new Sort(Sort.Direction.DESC, new String[]{ "orderNo","gmtCreated"})).skip(start).limit(limit);
- mongoTemplate 模糊匹配查询
Criteria criteria = new Criteria();
if (StringUtils.isNotBlank(keywords)) {
criteria.orOperator(Criteria.where("name").regex(keywords, "i"),
Criteria.where("comment").regex(keywords, "i"),
Criteria.where("referName").regex(keywords, "i")
);
}
根据字段排序
Query query = new Query(criteria).with(
new Sort(Sort.Direction.DESC, new String[]{ "orderNo","gmtCreated"}))
.skip(start).limit(limit);
- Robo 3T 查询
db.getCollection('xxxx').find({}).sort({gmtCreated:-1}) 倒序查询
db.getCollection('xxxx').find({comment:/曾经/}) 模糊匹配查询