mongoDB-Criteria

org.springframework.data.mongodb.core.query中Criteria类

SQL where conditions corresponding to the
attributes described:

Private  static  Final Object NOT_SET = new new Object (); 
@Nullable 
// store attribute value 
Private String Key;
 // store a set of conditions 
Private List <Criteria> criteriaChain;
 // Map collection, storage conditions are used, in addition to the representative method is outer conditions
 // others include lt, lte, gt, gte, ne, in, nin, mod, all, size, exists, not, regex or the like are stored in this map set. 
Private a LinkedHashMap <String, Object> Criteria = new new a LinkedHashMap (); 
@Nullable 
// used to store the value is passed in the method 
Private Object isValue;

Method (where, and):

// static methods, instance of a class name or object to call, he would create a Criteria object, the key parameter passed to this object, return the object 
public  static Criteria the WHERE (String key) {
     return  new new Criteria (key); 
}
// instance method, this method is called with the criteria objects, he creates and returns a new object, the object is placed in the original Criteria criteriachain property passed to the new object criteriachain 
public Criteria and (String Key) {
         return  new new Criteria ( the this .criteriaChain, Key); 
}

 Description:

criteriachain properties of the new object is created by where out in the new construction method, but by and then as a parameter constructor pass in.

A criteria object is saved only one condition, multiple conditions by multiple criteria save objects, each object is to create a criteria will add itself to your criteriachain property.

If you create an object reuse where, the previous conditions will be lost, because his criteriachain is new.

eg.

Criteria criteria = new Criteria();
criteria.and(key).is(value);

Guess you like

Origin www.cnblogs.com/sheng-yang/p/11880925.html