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);
}
知识兔