MongoDB 模糊查询,与查询
main(){
Query query = createFindQuery(bo);
primaryMongoDBDao.find(Bo.class, query);
}
/**
* 构造查询条件
*
* @param bo
* @return
*/
protected Query createFindQuery(BO bo) throws Exception {
Criteria criteria = Criteria.where("CreateTime").lte(bo.getEndTime()).gte(bo.getStartTime());
Query query = new Query();
if (StringUtils.isNotEmpty(bo.getName())) {
criteria.and("name").regex(".*?" + bo.getName() + ".*", "i");
}
query.addCriteria(criteria);
query.with(new Sort(Sort.Direction.DESC, "CreateTime"));
return query;
}