spring boot中 mongdb 多条件复杂查询

1.dao层继承MongoRepository

public interface PFlowLineStationHourDao extends MongoRepository{

}

2.service层注入PFlowLineStationHourDao ,MongoTemplate

例:

@Service

public class PFlowLineServiceImpl  implements PFlowLineService{

@Autowired

public PFlowLineStationHourDao pFlowLineStationHourDao;

@Autowired

        private MongoTemplate mongoTemplate;

        public List queryPFlowLineStationHour(PFlowQueryParam param) {
Query query = new Query();
if(param.getDates().size()>0){
query.addCriteria(Criteria.where("yearMonthDate").in(param.getDates()));
}else{
int beginDate = Integer.parseInt(DateUtil.getYearMonthDayFormat(DateUtil.getDayBefore(param.getBegintime())));
int endDate = Integer.parseInt(DateUtil.getYearMonthDayFormat(DateUtil.getDayAfter(param.getEndtime())));
query.addCriteria(Criteria.where("yearMonthDate").gte(beginDate).lte(endDate));
}
if(param.getLineCodes().size()>0){
query.addCriteria(Criteria.where("lineCode").in(param.getLineCodes()));
}
if(param.getStationnames().size()>0){
query.addCriteria(Criteria.where("stationname").in(param.getStationnames()));
}
if(param.getAreacodes().size()>0){
query.addCriteria(Criteria.where("areacode").in(param.getAreacodes()));
}
return mongoTemplate.find(query, PFlowLineStationHourEntity.class);
}

}


转载于:https://www.cnblogs.com/timeboy/p/9464402.html

你可能感兴趣的:(spring boot中 mongdb 多条件复杂查询)