Spring-data-mongodb Criteria类介绍

Criteria是Spring Data MongoDB中用于创建查询的核心类,提供了一种流畅的API来组合多个查询条件。通过静态导入`Criteria.where`方法可以提高代码的可读性。Criteria支持多种比较操作符,如$eq(等于)、$ne(不等于)、$lt(小于)、$lte(小于等于)、$gt(大于)、$gte(大于等于),以及$in、$nin、$mod等。此外,还支持$all、$size、$exists、$type等操作符,以及地理位置相关的查询操作,如$near、$nearSphere等。Criteria类允许使用$elemMatch、$or、$nor和$and操作符来组合复杂查询条件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

类 Criteria

  • java.lang.Object
    • org.springframework.data.mongodb.core.query.Criteria
  • 所有已实现的接口:
    CriteriaDefinition
    直接已知子类:
    GridFsCriteria


    public class Criteria
    extends java.lang.Object
    implements CriteriaDefinition
    Central class for creating queries. It follows a fluent API style so that you can easily chain together multiple criteria. Static import of the 'Criteria.where' method will improve readability.
    • 构造器概要

      构造器  
      限定符构造器和说明
       Criteria() 
      protected Criteria(java.util.List<Criteria> criteriaChain, java.lang.String key) 
       Criteria(java.lang.String key) 
    • 方法概要

      方法  
      限定符和类型方法和说明
      Criteriaall(java.util.Collection<?> o) 
      Criteriaall(java.lang.Object... o)
      Creates a criterion using the $all operator
      Criteriaand(java.lang.String key)
      Static factory method to create a Criteria using the provided key
      CriteriaandOperator(Criteria... criteria)
      Creates an 'and' criteria using the $and operator for all of the provided criteria
      CriteriaelemMatch(Criteria c)
      Creates a criterion using the $elemMatch operator
      booleanequals(java.lang.Object obj) 
      Criteriaexists(boolean b)
      Creates a criterion using the $exists operator
      DBObjectgetCriteriaObject() 
      java.lang.StringgetKey() 
      protected DBObjectgetSingleCriteriaObject() 
      Criteriagt(java.lang.Object o)
      Creates a criterion using the $gt operator
      Criteriagte(java.lang.Object o)
      Creates a criterion using the $gte operator
      inthashCode() 
      Criteriain(java.util.Collection<?> c)
      Creates a criterion using the $in operator
      Criteriain(java.lang.Object... o)
      Creates a criterion using the $in operator
      Criteriais(java.lang.Object o)
      Creates a criterion using equality
      Criterialt(java.lang.Object o)
      Creates a criterion using the $lt operator
      Criterialte(java.lang.Object o)
      Creates a criterion using the $lte operator
      CriteriamaxDistance(double maxDistance)
      Creates a geospatical criterion using a $maxDistance operation, for use with $near
      Criteriamod(java.lang.Number value, java.lang.Number remainder)
      Creates a criterion using the $mod operator
      Criteriane(java.lang.Object o)
      Creates a criterion using the $ne operator
      Criterianear(Point point)
      Creates a geospatial criterion using a $near operation
      CriterianearSphere(Point point)
      Creates a geospatial criterion using a $nearSphere operation.
      Criterianin(java.util.Collection<?> o) 
      Criterianin(java.lang.Object... o)
      Creates a criterion using the $nin operator
      CriterianorOperator(Criteria... criteria)
      Creates a 'nor' criteria using the $nor operator for all of the provided criteria
      Criterianot()
      Creates a criterion using the $not meta operator which affects the clause directly following
      CriteriaorOperator(Criteria... criteria)
      Creates an 'or' criteria using the $or operator for all of the provided criteria
      Criteriaregex(java.util.regex.Pattern pattern)
      Syntactical sugar for is(Object) making obvious that we create a regex predicate.
      Criteriaregex(java.lang.String re)
      Creates a criterion using a $regex
      Criteriaregex(java.lang.String re, java.lang.String options)
      Creates a criterion using a $regex and $options
      Criteriasize(int s)
      Creates a criterion using the $size operator
      Criteriatype(int t)
      Creates a criterion using the $type operator
      static Criteriawhere(java.lang.String key)
      Static factory method to create a Criteria using the provided key
      Criteriawithin(Shape shape) 
      CriteriawithinSphere(Circle circle)
      Creates a geospatial criterion using a $within $center operation.
      • 从类继承的方法 java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • 构造器详细资料

      • Criteria
        public Criteria()
      • Criteria
        public Criteria(java.lang.String key)
      • Criteria
        protected Criteria(java.util.List<Criteria> criteriaChain,
                java.lang.String key)
    • 方法详细资料

      • where
        public static Criteria where(java.lang.String key)
        Static factory method to create a Criteria using the provided key
        参数:
        key -
        返回:
      • and
        public Criteria and(java.lang.String key)
        Static factory method to create a Criteria using the provided key
        返回:
      • is
        public Criteria is(java.lang.Object o)
        Creates a criterion using equality
        参数:
        o -
        返回:
      • ne
        public Criteria ne(java.lang.Object o)
        Creates a criterion using the $ne operator
        参数:
        o -
        返回:
      • lt
        public Criteria lt(java.lang.Object o)
        Creates a criterion using the $lt operator
        参数:
        o -
        返回:
      • lte
        public Criteria lte(java.lang.Object o)
        Creates a criterion using the $lte operator
        参数:
        o -
        返回:
      • gt
        public Criteria gt(java.lang.Object o)
        Creates a criterion using the $gt operator
        参数:
        o -
        返回:
      • gte
        public Criteria gte(java.lang.Object o)
        Creates a criterion using the $gte operator
        参数:
        o -
        返回:
      • in
        public Criteria in(java.lang.Object... o)
        Creates a criterion using the $in operator
        参数:
        o - the values to match against
        返回:
      • in
        public Criteria in(java.util.Collection<?> c)
        Creates a criterion using the $in operator
        参数:
        c - the collection containing the values to match against
        返回:
      • nin
        public Criteria nin(java.lang.Object... o)
        Creates a criterion using the $nin operator
        参数:
        o -
        返回:
      • nin
        public Criteria nin(java.util.Collection<?> o)
      • mod
        public Criteria mod(java.lang.Number value,
                   java.lang.Number remainder)
        Creates a criterion using the $mod operator
        参数:
        value -
        remainder -
        返回:
      • all
        public Criteria all(java.lang.Object... o)
        Creates a criterion using the $all operator
        参数:
        o -
        返回:
      • all
        public Criteria all(java.util.Collection<?> o)
      • size
        public Criteria size(int s)
        Creates a criterion using the $size operator
        参数:
        s -
        返回:
      • exists
        public Criteria exists(boolean b)
        Creates a criterion using the $exists operator
        参数:
        b -
        返回:
      • type
        public Criteria type(int t)
        Creates a criterion using the $type operator
        参数:
        t -
        返回:
      • not
        public Criteria not()
        Creates a criterion using the $not meta operator which affects the clause directly following
        返回:
      • regex
        public Criteria regex(java.lang.String re)
        Creates a criterion using a $regex
        参数:
        re -
        返回:
      • regex
        public Criteria regex(java.lang.String re,
                     java.lang.String options)
        Creates a criterion using a $regex and $options
        参数:
        re -
        options -
        返回:
      • regex
        public Criteria regex(java.util.regex.Pattern pattern)
        Syntactical sugar for is(Object) making obvious that we create a regex predicate.
        参数:
        pattern -
        返回:
      • withinSphere
        public Criteria withinSphere(Circle circle)
        Creates a geospatial criterion using a $within $center operation. This is only available for Mongo 1.7 and higher.
        参数:
        circle - must not be null
        返回:
      • near
        public Criteria near(Point point)
        Creates a geospatial criterion using a $near operation
        参数:
        point - must not be null
        返回:
      • nearSphere
        public Criteria nearSphere(Point point)
        Creates a geospatial criterion using a $nearSphere operation. This is only available for Mongo 1.7 and higher.
        参数:
        point - must not be null
        返回:
      • maxDistance
        public Criteria maxDistance(double maxDistance)
        Creates a geospatical criterion using a $maxDistance operation, for use with $near
        参数:
        maxDistance -
        返回:
      • elemMatch
        public Criteria elemMatch(Criteria c)
        Creates a criterion using the $elemMatch operator
        参数:
        c -
        返回:
      • orOperator
        public Criteria orOperator(Criteria... criteria)
        Creates an 'or' criteria using the $or operator for all of the provided criteria
        参数:
        criteria -
      • norOperator
        public Criteria norOperator(Criteria... criteria)
        Creates a 'nor' criteria using the $nor operator for all of the provided criteria
        参数:
        criteria -
      • andOperator
        public Criteria andOperator(Criteria... criteria)
        Creates an 'and' criteria using the $and operator for all of the provided criteria
        参数:
        criteria -
      • getKey
        public java.lang.String getKey()
      • getSingleCriteriaObject
        protected DBObject getSingleCriteriaObject()
      • equals
        public boolean equals(java.lang.Object obj)
        覆盖:
        equals 在类中  java.lang.Object
      • hashCode
        public int hashCode()
        覆盖:
        hashCode 在类中  java.lang.Object
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值