3.4.1. 条件查询策略

The following strategies are available for the repository infrastructure to resolve the query. You can configure the strategy at the namespace through the query-lookup-strategy attribute in case of XML configuration or via the queryLookupStrategy attribute of the Enable${store}Repositories annotation in case of Java config. Some strategies may not be supported for particular datastores.

repository 可以通过下面三种策略来解析查询。你可以使用XML配置的query-lookup-strategy属性,或者使用JAVA配置的---通过Enable${store}Repositories进行声明 --- queryLookupStrategy属性。有些特别的 datastores 可能不支持某些策略。

CREATE attempts to construct a store-specific query from the query method name. The general approach is to remove a given set of well-known prefixes from the method name and parse the rest of the method. Read more about query construction in Query creation.

CREATE 策略按照接口名称自动构建查询,通过移除已知的前缀并解析剩余的部分,具体请参照 创建查询 章节。

USE_DECLARED_QUERY tries to find a declared query and will throw an exception in case it can’t find one. The query can be defined by an annotation somewhere or declared by other means. Consult the documentation of the specific store to find available options for that store. If the repository infrastructure does not find a declared query for the method at bootstrap time, it fails.

USE_DECLARED_QUERY策略优先使用用户声明的查询条件,找不到则会抛出一个异常。 这个查询可以使用注解或是其他方式声明。

CREATE_IF_NOT_FOUND (default) combines CREATE and USE_DECLARED_QUERY. It looks up a declared query first, and if no declared query is found, it creates a custom method name-based query. This is the default lookup strategy and thus will be used if you do not configure anything explicitly. It allows quick query definition by method names but also custom-tuning of these queries by introducing declared queries as needed.

CREATE_IF_NOT_FOUND策略(默认)是前面两种策略的结合体。它首先尝试使用声明的查询条件,如果失败则尝试自动创造查询。如果你不进行任何配置那么这就是默认的策略。它能够让你通过方法名快速的定义查询,也可以通过引入所需的声明自定义查询。

results matching ""

    No results matching ""