我正在使用Spring Data JPA,当我使用@Query
来定义一个没有Pageable
的查询时,它可以工作:
我使用Spring Data JPA,当我使用@Query
定义一个没有Pageable
的查询时,它是有效的:
public interface UrnMappingRepository extends JpaRepository<UrnMapping, Long> {
@Query(value = "select * from internal_uddi where urn like %?1% or contact like %?1%",
nativeQuery = true)
List<UrnMapping> fullTextSearch(String text);
}
但如果我添加第二个参数Pageable
,@Query
将无法工作,Spring将解析方法的名称,然后抛出异常No property full found
。这是一个错误吗?
public interface UrnMappingRepository extends JpaRepository<UrnMapping, Long> {
@Query(value = "select * from internal_uddi where urn like %?1% or contact like %?1%",
nativeQuery = true)
Page<UrnMapping> fullTextSearch(String text, Pageable pageable);
}
countQuery
也适用于非本地化查询,其中Spring无法从原始查询中推导出元素数量。 - darefilzcountQuery
不适合您。它会触发另一个计数查询来实现它。为了避免这样的开销,您可以返回Slice<T>
或List<T>
。 - jumping_monkey