zoukankan      html  css  js  c++  java
  • mongoTemplate关联查询


    //主表c_stu_homework关联两张表c_course和c_category,localField()从表关联条件,foreignField()主表的关联条件,as()别名 LookupOperation courseLookupOperation = LookupOperation.newLookup(). from("c_course"). localField("courseId"). foreignField("id"). as("course"); LookupOperation categoryLookupOperation = LookupOperation.newLookup(). from("c_category"). localField("homewkId"). foreignField("homewkId"). as("category"); String startDate = DateUtils.dateToString1(new Date()) + " 00:00:00"; String endDate = DateUtils.dateToString1(new Date()) + " 23:59:59"; //条件和查询的字段 Criteria cri = Criteria.where("createTime").gte(startDate).lte(endDate); AggregationOperation match = Aggregation.match(cri); ProjectionOperation project = Aggregation.project("id", "stuId", "homewkId", "homewkName", "category.categoryName", "completeStatus", "score", "createTime", "endTime", "courseId", "course.courseName", "orgId", "tchId", "tchName", "courseUnitId", "course.textbookId", "course.textbookVersionId", "course.textLevelId"); //将以上的条件封装 List<AggregationOperation> operations = new ArrayList<>(); operations.add(courseLookupOperation); operations.add(categoryLookupOperation); operations.add(match); operations.add(project); Aggregation aggregation = Aggregation.newAggregation(operations); AggregationResults<StudentHomeEntity> results = mongoTemplate.aggregate(aggregation, "c_stu_homework", StudentHomeEntity.class); List<StudentHomeEntity> mappedResults = results.getMappedResults();
    
    
    
    
  • 相关阅读:
    泰山之行
    泰山之行
    Java EE (2) -- Java EE 6 Enterprise JavaBeans Developer Certified Expert(1z0-895)
    一、浏览器生成消息(2)
    P1194 买礼物 洛谷
    P1195 口袋的天空 洛谷
    P1546||2627 最短网络 Agri-Net 洛谷||codevs
    P3366 最小生成树【模板】 洛谷
    T2627 村村通 codevs
    【目录】我的原创技术视频教程
  • 原文地址:https://www.cnblogs.com/handongxue/p/13224484.html
Copyright © 2011-2022 走看看