【发布时间】:2020-06-24 15:19:21
【问题描述】:
例如我有 Repository 类:
public interface PersonRepo extends JpaRepository<Person, Long>, JpaSpecificationExecutor<Person>
我想使用 JpaSpecificationExecutor 提供的 findAll() 方法。
如果我想获取所有用户,它会返回完整的用户 DTO-s,包括加密密码和用户角色等...
PersonRepo.findAll()
我如何告诉 findAll 只发送姓名和电子邮件而不是所有内容。
我使用 Mapstruct 将我的 Person 类转换为 PersonDTO。
【问题讨论】:
-
保持 findAll() 不变。您可以创建调用 findAll() 并存储在本地列表中的方法。然后你可以过滤你想要的并返回新的列表
标签: java spring jpa dto findall