Criteria c1= Criteria.where("year").gte(startYear).lte(endYear).and("month").is(endMonth).and("day").gte(startDay).lte(endDay) .and("hour").gte(startHour).lte(endHour).and("minute").is(startMinute).and("second").gte(startSecond); Criteria c2=Criteria.where("year").gte(startYear).lte(endYear).and("month").is(endMonth).and("day").gte(startDay).lte(endDay) .and("hour").gte(startHour).lte(endHour).and("minute").is(endMinute).and("second").lte(endSecond); Criteria c3 =Criteria.where("year").gte(startYear).lte(endYear).and("month").is(endMonth).and("day").gte(startDay).lte(endDay) .and("hour").gte(startHour).lte(endHour).and("minute").gt(startMinute).lt(endMinute); Criteria cr = new Criteria(); query = new Query(cr.orOperator(c1,c2,c3)); getMongoTemplate().find(query, SensorCollection.class);
附带Criteria方法:
Criteria
Mongodb | 说明 | |
Criteria and (String key) | $and | 并且 |
Criteria andOperator (Criteria… criteria) | $and | 并且 |
Criteria orOperator (Criteria… criteria) | $or | 或者 |
Criteria gt (Object o) | $gt | 大于 |
Criteria gte (Object o) | $gte | 大于等于 |
Criteria in (Object… o) | $in | 包含 |
Criteria is (Object o) | $is | 等于 |
Criteria lt (Object o) | $lt | 小于 |
Criteria lte (Object o) | $lte | 小等于 |
Criteria nin (Object… o) | $nin | 不包含 |
博客
http://blog.csdn.net/congcong68/article/details/52821362