Skip to content

This project is an example of how can we build advanced query search with Spring Data JPA.

Notifications You must be signed in to change notification settings

pedrohenriquelacombe/spring-rest-advanced-search-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring REST Advanced Search example

This project is an example of how can we build advanced query search with Spring Data JPA.

About

The main goal of this project is to show two forms that we can build advanced query search with Spring Data JPA.

  • First one, mapped as version 1 ("/persons/v1"), we are implementing a custom repository and using the EntityManager for build our condition query;
  • Second one, mapped as version 2 ("/persons/v2"), implementated using Spring Data JPA Specifications;

You can use both routes, /v1 or /v2. They will bring the same response, the only difference is thay they are implemented in differentes ways. Check below for some examples.

Advanced Search examples:

localhost:8080/persons/v1?name=Ma
localhost:8080/persons/v1?name=Ma&email=pedro@
localhost:8080/persons/v1?name=Ma&email=pedro@&maritalStatus=MARRIED
localhost:8080/persons/v1?name=Ma&email=pedro@&maritalStatus=MARRIED&district=Tijuca
localhost:8080/persons/v1?name=Ma&email=pedro@&maritalStatus=MARRIED&district=Tijuca&city=Rio de Janeiro
localhost:8080/persons/v1?name=Ma&email=pedro@&maritalStatus=MARRIED&state=RJ

Pagination and Sorting examples:

localhost:8080/persons/v1?pageSize=5
localhost:8080/persons/v1?pageSize=5&pageNumber=0
localhost:8080/persons/v1?sortBy=name&orderBy=asc
localhost:8080/persons/v1?pageSize=5&pageNumber=0&sortBy=name&orderBy=desc

Technologies

Features

  • DTO (Data Transfer Object) principles
  • Advanced query search with:
    • Spring Data JPA Specifications
    • TypedQuery way
  • Custom Exception Handler messages

Built With

How can I test my endpoints?

First, open your preference code editor and run the following code below:

mvn clean install

After the maven downloaded all dependencies, run the SpringRestAdvancedSearchApplication.class.

For tests cases, you can check the API endpoints with Postman.

About

This project is an example of how can we build advanced query search with Spring Data JPA.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages