Repository query keywords

支援的查詢方法主詞關鍵字

下表列出了 Spring Data 儲存庫查詢衍生機制通常支援的主詞關鍵字,用於表達述詞。請查閱特定儲存庫的文件以取得支援關鍵字的確切清單,因為此處列出的一些關鍵字可能在特定儲存庫中不受支援。

Table 1. Query subject keywords
Keyword Description

find…By, read…By, get…By, query…By, search…By, stream…By

通用查詢方法,通常傳回儲存庫類型、CollectionStreamable 子類型,或結果包裝器,例如 PageGeoResults 或任何其他儲存庫特定的結果包裝器。 可以用作 findBy…findMyDomainTypeBy… 或與其他關鍵字組合使用。

exists…By

Exists 投影,通常傳回 boolean 結果。

count…By

Count 投影,傳回數值結果。

delete…By, remove…By

Delete 查詢方法,不傳回任何結果 (void) 或傳回刪除計數。

…First<number>…, …Top<number>…

將查詢結果限制為前 <number> 個結果。 此關鍵字可以出現在主詞中 find (和其他關鍵字) 和 by 之間的任何位置。

…Distinct…

使用 distinct 查詢僅傳回唯一結果。 請查閱特定儲存庫的文件,以瞭解是否支援該功能。 此關鍵字可以出現在主詞中 find (和其他關鍵字) 和 by 之間的任何位置。

保留方法

下表列出了使用預定義功能(如 CrudRepository 中定義)的保留方法。 這些方法直接在儲存庫代理的後端(特定於儲存庫)實作上調用。另請參閱「定義查詢方法」。

Table 2. Reserved methods

deleteAllById(Iterable<ID> identifiers)

deleteById(ID identifier)

existsById(ID identifier)

findAllById(Iterable<ID> identifiers)

findById(ID identifier)

支援的查詢方法述詞關鍵字和修飾詞

下表列出了 Spring Data 儲存庫查詢衍生機制通常支援的述詞關鍵字。 但是,請查閱特定儲存庫的文件以取得支援關鍵字的確切清單,因為此處列出的一些關鍵字可能在特定儲存庫中不受支援。

Table 3. Query predicate keywords
Logical keyword Keyword expressions

AND

And

OR

Or

AFTER

After, IsAfter

BEFORE

Before, IsBefore

CONTAINING

Containing, IsContaining, Contains

BETWEEN

Between, IsBetween

ENDING_WITH

EndingWith, IsEndingWith, EndsWith

EXISTS

Exists

FALSE

False, IsFalse

GREATER_THAN

GreaterThan, IsGreaterThan

GREATER_THAN_EQUALS

GreaterThanEqual, IsGreaterThanEqual

IN

In, IsIn

IS

Is, Equals, (或沒有關鍵字)

IS_EMPTY

IsEmpty, Empty

IS_NOT_EMPTY

IsNotEmpty, NotEmpty

IS_NOT_NULL

NotNull, IsNotNull

IS_NULL

Null, IsNull

LESS_THAN

LessThan, IsLessThan

LESS_THAN_EQUAL

LessThanEqual, IsLessThanEqual

LIKE

Like, IsLike

NEAR

Near, IsNear

NOT

Not, IsNot

NOT_IN

NotIn, IsNotIn

NOT_LIKE

NotLike, IsNotLike

REGEX

Regex, MatchesRegex, Matches

STARTING_WITH

StartingWith, IsStartingWith, StartsWith

TRUE

True, IsTrue

WITHIN

Within, IsWithin

In addition to filter predicates, the following list of modifiers is supported

Table 4. Query predicate modifier keywords
Keyword Description

IgnoreCase, IgnoringCase

與述詞關鍵字一起使用,用於不區分大小寫的比較。

AllIgnoreCase, AllIgnoringCase

忽略所有適用屬性的大小寫。 用於查詢方法述詞中的某處。

OrderBy…

指定靜態排序順序,後跟屬性路徑和方向(例如 OrderByFirstnameAscLastnameDesc)。