5.3.1. 查询策略

5.3.1. 查询策略

5.3.1. Query Lookup Strategies

JPA模块支持手动定义一个查询为字符串,或者通过方法命名推导。

The JPA module supports defining a query manually as a String or having it being derived from the method name.

声明查询

Declared Queries

虽然从方法名中推导得到查询的方式比较便捷,但也会面临一个问题,方法名解析器不支持要用到的关键词,或者通过方法名得到的不是预期的结果。所以你可以通过命名规范(请查阅使用JPA命名查询来获取更多信息)来使用JPA命名查询,或者使用@Query(请查询使用@Query获取更新信息)来注解你的查询方法。

Although getting a query derived from the method name is quite convenient, one might face the situation in which either the method name parser does not support the keyword one wants to use or the method name would get unnecessarily ugly. So you can either use JPA named queries through a naming convention (see Using JPA Named Queries for more information) or rather annotate your query method with @Query (see Using @Query for details).

翻译部分版权归YahaCode团队所有。仅供学习研究之用,任何组织或个人不得私自以此用于任何形式的商业目的

发表评论