Skip to content

djselzlein/spring-data-query-methods-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Data Query Methods Demo

Build Status

Use Spring Data to generate database query methods by method names.

What for?

Spring Data repositories implement a strategy for generating database query methods from the method's names themselves.

Spring Data JpaRepository:

interface JpaRepository<T, ID extends Serializable>

Create an interface repository for your model by extending JpaRepository like this:

interface AddressRepository extends JpaRepository<Address, Long>

In your interface you can add method signatures following Spring Data Query Methods' strategy:

Set<Customer> findByBirthdayBetween(LocalDate startDate, LocalDate endDate);

Set<Customer> findByAddress_ZipCode(String zipCode);

By following this strategy, Spring Data will generate implementation for these methods and you will be able to use them without having to write a single JPQL (Java Persistence Query Language) line nor the worst case, native SQL.

Check tests in this project for a better comprehension.

See this blog post for a complete guidance on implementing Spring Data Query Methods.

See Spring Data documentation for further details.

Run

  • Clone
  • mvn test

About

Demo on how to understand and use Spring Data Query Methods

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages