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

Viewed 152

for example i have Repository class :

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

and i want to use findAll() method provided by JpaSpecificationExecutor.

if i want to get all users it returns full user DTO-s including encripted passwords and user roles etc...

PersonRepo.findAll()

How can i tell findAll to send only name and email for example instead of everything.

I use Mapstruct to convert my Person Class to PersonDTO.

1 Answers

As mentioned here, you will have to define your own method and use the @Query annotation for it.

Related