zoukankan      html  css  js  c++  java
  • spring boot中 mongdb 多条件复杂查询

    1.dao层继承MongoRepository

    public interface PFlowLineStationHourDao extends MongoRepository<PFlowLineStationHourEntity, Long>{

    }

    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);
    }

    }


  • 相关阅读:
    又见JavaWeb的中文乱码
    Java 中文字符串编码之GBK转UTF-8
    关于Java项目打包
    FreeSWITCH无法读取wav文件
    CentOS 7 最小化安装的网络配置
    虚拟机无法使用网卡桥接模式
    阿里云建站流程
    Spring MVC无法获取ajax POST的参数和值
    Mysql ERROR 1064 (42000)
    eclipse创建java类时自动添加注释
  • 原文地址:https://www.cnblogs.com/timeboy/p/9464402.html
Copyright © 2011-2022 走看看