Dennis Podbicanin
Dennis Podbicanin

Reputation: 21

Spring Data JPA - Get all elements

I'm new to Spring Data JPA and I want to ask if there is a method that can be used to fetch all items, not by a certain criterion. Any help would be helpful.

Upvotes: 1

Views: 10417

Answers (1)

Panagiotis Bougioukos
Panagiotis Bougioukos

Reputation: 18919

Use the findAll method from repository

repository.findAll()

Take a look here

Spring Data JPA API

Look here a small example that will fetch all MyObj objects that are stored

@Repository
public interface MyObjRepository extends JpaRepository<MyObj, Long> { }

@Service
public class MyService {

@Autowired
MyObjRepository repository;

public List<MyObj> findAllElements() {
  return repository.findAll();
 }

}

Upvotes: 2

Related Questions