Browsed by
月份:2018年12月

4.6. Spring Data库的自定义实现

4.6. Spring Data库的自定义实现

4.6. Custom Implementations for Spring Data Repositories 此章节覆盖了库的自定义与如何组合一个复合库。 This section covers repository customization and how fragments form a composite repository. 当一个查询方法需要不同的行为,或者无法由查询导出实现,就有必要提供一个自定义的实现。Spring Data库允许你提供一个自定义库并于泛型CRUD抽象和查询方法功能集成。 When a query method requires a different behavior or cannot be implemented by query derivation, then it is necessary to provide a custom implementation. Spring Data repositories let you provide custom repository code and integrate it with generic CRUD abstraction and query method functionality. 4.6.1. 自定义个体库 4.6.1. Customizing Individual Repositories 为了让自定义功能来丰富一个库,你必须先定义一个片段接口和与一个自定义功能的实现,如下例所示: To…

阅读全文 Read More

5.3.9. 应用查询提示

5.3.9. 应用查询提示

5.3.9. Applying Query Hints 为了在库接口声明的查询上应用JPA查询提示,可以使用@QueryHints注解。接收参数为JPA @QueryHint注解数组,和一个为了在应用分页时,用于失效提示应用被计数查询触发的布尔值,如下例所示: To apply JPA query hints to the queries declared in your repository interface, you can use the @QueryHints annotation. It takes an array of JPA @QueryHint annotations plus a boolean flag to potentially disable the hints applied to the additional count query triggered when applying pagination, as shown in the following example: 例66. 在库方法上使用QueryHints Example 66. Using QueryHints with a repository method public interface UserRepository extends Repository<User, Long> { @QueryHints(value = { @QueryHint(name = “name”, valu…

阅读全文 Read More

5.3.8. 修改查询

5.3.8. 修改查询

5.3.8. Modifying Queries 前面的章节都描述了如何声明查询,来得到一个指定的实体或者实体集合。你可以使用“Spring Data库的自定义实现”中描述的工具,来添加一个自定义的修改行为。此方法对于大多数自定义功能都可用,你只需要通过@Modifying注解查询方法并绑定参数,就可以修改查询,如下例所示: All the previous sections describe how to declare queries to access a given entity or collection of entities. You can add custom modifying behavior by using the facilities described in “Custom Implementations for Spring Data Repositories”. As this approach is feasible for comprehensive custom functionality, you can modify queries that only need parameter binding by annotating the query method with @Modifying, as shown in the following example: 例64. 声明操作查询 Example 64. Declaring manipulating q…

阅读全文 Read More