I want to create a search filter in Spring Boot controller, that takes 6 paramas and param value may be null then how to write a Data JPA Query?

Viewed 20

Like I have a page where data are showing like first name, middle name, last name, address, city, state, country, age, salary.

There are a filter implemented that have 4 fields like city, age, salary, state. now I have to made a controller in Spring boot that takes all 4 fields as input params and find data from database using Spring Data JPA.

But my problem is that I want to filter Data sometime by salary only, sometime by city, state, sometime with all 4 params. So what will be controller code and JPA Repository query to do this filter process.

Please Help me Thanks in Advance

1 Answers

test if your parameters are null :

"where (:name is null or name = :name) and (:city is null or city = :city)"
Related