有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

从方法名创建java查询无效。正在尝试筛选可分页的

我试图通过表上的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) 个答案

  1. # 1 楼答案

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

    如果属性实际名为isPrivate,即getter名为isIsPrivategetIsPrivate,则方法名应为findByIsPrivate