zoukankan      html  css  js  c++  java
  • mongodb and 和 or 查询

    db.getCollection('gxyWarnEntity').find({ "schoolId" : "f11c8ea12f457dbc19c768a8bb6357f8", "batchId" : "594f724d6974c107bd702cc6ef39183a", "$or" : [{ "studentName" : { "$regex" : "小", "$options" : "" } }, { "teacherName" : { "$regex" : "小", "$options" : "" } }] })

    java:

       public List<GxyWarnEntity>  selectWarnPage(GxyWarnEntity  gxyWarnEntity){
    
            Criteria cri =Criteria.where("schoolId").is(gxyWarnEntity.getSchoolId());
    
            if(gxyWarnEntity.getBatchId()!=null) {
                cri.and("batchId").is(gxyWarnEntity.getBatchId());
            }
            if(gxyWarnEntity.getDepId()!=null){
                cri.and("depId").is(gxyWarnEntity.getDepId());
            }
            if(gxyWarnEntity.getWarningType()!=null){
                cri.and("warningType").is(gxyWarnEntity.getWarningType());
            }
            if(gxyWarnEntity.getStudentName()!=null){
                cri.orOperator(Criteria.where("studentName").regex(gxyWarnEntity.getStudentName()),
                        Criteria.where("teacherName").regex(gxyWarnEntity.getStudentName())
                        //,Criteria.where("classTeacherName").regex(gxyWarnEntity.getStudentName())
                );
            }
    
            Query query = new Query(cri);
            if (gxyWarnEntity.getCurrPage() != null && gxyWarnEntity.getPageSize() != null) {
                query.skip((gxyWarnEntity.getCurrPage()-1)*gxyWarnEntity.getPageSize())
                        .limit(gxyWarnEntity.getPageSize());
            }
    
            return template.find(query, GxyWarnEntity.class);
        }

    and:   

    db.getCollection('gxyWarnEntity').find({ "schoolId" : "f11c8ea12f457dbc19c768a8bb6357f8", "batchId" : "", "$and" : [{ "warningType" : { "$gte" : 1 } }, { "warningType" : { "$ne" : 4 } }], "$or" : [{ "studentName" : { "$regex" : "小", "$options" : "" } }, { "teacherName" : { "$regex" : "小", "$options" : "" } }] })

    { "schoolId" : "f11c8ea12f457dbc19c768a8bb6357f8", "batchId" : "", "$and" : [{ "warningType" : { "$gte" : 1 } }, { "warningType" : { "$ne" : 4 } }], "$or" : [{ "studentName" : { "$regex" : "小", "$options" : "" } }, { "teacherName" : { "$regex" : "小", "$options" : "" } }] } fields: Document{{}} for class: class com.zhangtao.moguding.practiceservice.entity.GxyWarnEntity in collection: gxyWarnEntity
    2019-10-15 09:52:17.819 DEBUG 13028 --- [io-9020-exec-15] o.s.data.mongodb.core.MongoTemplate : Executing count: { "schoolId" : "f11c8ea12f457dbc19c768a8bb6357f8", "batchId" : "", "$and" : [{ "warningType" : { "$gte" : 1 } }, { "warningType" : { "$ne" : 4 } }], "$or" : [{ "studentName" : { "$regex" : "小", "$options" : "" } }, { "teacherName" : { "$regex" : "小", "$options" : "" } }] } in collection: gxyWarnEntity

        public List<GxyWarnEntity>  selectWarnPage(GxyWarnEntity  gxyWarnEntity){
    
            Criteria cri =Criteria.where("schoolId").is(gxyWarnEntity.getSchoolId());
    
            if(gxyWarnEntity.getBatchId()!=null) {
                cri.and("batchId").is(gxyWarnEntity.getBatchId());
            }
            if(gxyWarnEntity.getDepId()!=null){
                cri.and("depId").is(gxyWarnEntity.getDepId());
            }
            if(gxyWarnEntity.getWarningType()!=null && gxyWarnEntity.getWarningType() != EnumUnsignType.UNSIGNONE.getType()){
                cri.andOperator(
                        Criteria.where("warningType").gte(gxyWarnEntity.getWarningType()),
                        Criteria.where("warningType").ne(EnumUnsignType.UNSIGNONE.getType())
                );
            }
            if(gxyWarnEntity.getStudentName()!=null){
                cri.orOperator(Criteria.where("studentName").regex(gxyWarnEntity.getStudentName()),
                        Criteria.where("teacherName").regex(gxyWarnEntity.getStudentName())
                        //,Criteria.where("classTeacherName").regex(gxyWarnEntity.getStudentName())
                );
            }
    
            Query query = new Query(cri);
            if (gxyWarnEntity.getCurrPage() != null && gxyWarnEntity.getPageSize() != null) {
                query.skip((gxyWarnEntity.getCurrPage()-1)*gxyWarnEntity.getPageSize())
                        .limit(gxyWarnEntity.getPageSize());
            }
    
            return template.find(query, GxyWarnEntity.class);
        }
  • 相关阅读:
    在IDEA(phpStorm)中使用Babel编译ES6
    vue2.0使用记录
    透过一道面试题来探探JavaScript中执行上下文和变量对象的底
    详解Object.constructor
    javascript数组操作
    项目协作
    关于@BindingResult bindingresult...
    在Java中使用Jedis的测试案例
    数据库性能优化之SQL语句优化(转 java知音)
    SpringBoot之集成Spring AOP
  • 原文地址:https://www.cnblogs.com/z360519549/p/11635366.html
Copyright © 2011-2022 走看看