我如何 return 只使用 findAll() 而不是所有的特定信息?

How can i return only specific information with findAll() instead of everything?

例如我有存储库 class :

public interface PersonRepo extends JpaRepository<Person, Long>, JpaSpecificationExecutor<Person>

我想使用 JpaSpecificationExecutor 提供的 findAll() 方法。

如果我想获得所有用户 returns 完整的用户 DTO-s,包括加密的密码和用户角色等...

PersonRepo.findAll()

我如何告诉 findAll 仅发送姓名和电子邮件,而不是所有内容。

我使用 Mapstruct 将我的 Person Class 转换为 PersonDTO。

如前所述 here,您必须定义自己的方法并为其使用 @Query 注释。