从方法名称创建查询无效。尝试过滤可分页

时间:2019-05-15 20:31:30

标签: java spring-boot spring-data-jpa

我正在尝试通过表上的isPrivate布尔列过滤返回的分页数据集。我相信我应该能够通过添加以下方法名称来创建查询。

我一直在阅读spring文档(https://docs.spring.io/spring-data/jpa/docs/1.5.0.RELEASE/reference/html/repositories.html#repositories.create-instances.java-config),我再次检查了我的数据库配置中是否具有@EnableJpaRepositories(“ // Project here”)批注。我可以打电话给findall,它按预期工作。

public interface AnnouncementRepository extends JpaRepository<Announcement, Long> {
    Page<Announcement> findByisPrivate(boolean isPrivate, Pageable page);
}

错误:

 org.springframework.beans.factory.UnsatisfiedDependencyException:
 Error creating bean with name 'announcementResource' defined in file

1 个答案:

答案 0 :(得分:0)

isPrivate可能不是属性名称,而是它的获取器,它将使private成为其名称。 因此,查询方法应命名为findByPrivate

如果该属性实际上被命名为isPrivate,即该getter被命名为isIsPrivategetIsPrivate,则方法名称应为findByIsPrivate

相关问题