Spring 数据 JPA 投影 - 获取投影列的所有行

Spring data JPA projection - get all rows for the projected columns

我正在尝试使用 Spring 数据 JPA 投影来获取数据库中的特定列。在我的设置中,我的实体 class 具有表示列的字段,并且我还创建了一个视图来获取投影数据。我在 在存储库 class 中创建方法时遇到问题。我想获取数据库中该视图的所有行(我不想查询,比如 getPersonViewById),但是 Spring 抱怨:

java.lang.IllegalArgumentException: Failed to create query for method

当我将 Repository 中的方法更改为 getPersonViewById() 时,它工作正常。

知道存储库中的查询如何 class 吗?这是我的代码:

@Entity
public class Person {
    
    @Id
    @Column (name = "id")
    private final UUID id;
    
    @Column (name = "name")
    private String name;
    
    @Column (name = "address")
    private String address;
    
    public UUID getId () {
        return id;
    }
    
    public String getName () {
        return name;
    }
    
    public interface PersonView {
        String getName();
        String getId();
    }
    
}

@Repository
public interface PersonRepository extends Repository<Person, Long> {
    List<PersonView> getPersonView ();
}

我找到了这个问题的答案。如果我使用 getPersonViewBy(),在方法名称 'By' 之后没有任何内容,它将 return 所有行。