I am using spring-data-jpa
here is my query
@Query(value = "select ea.* from employee ea where ids in (?1) and (?2 is null or country=?2) ", nativeQuery = true)
Page<Employee> findByds(List<UUID> ids,String country ,Pageable pageable );
I want to get list of employee by matching country only when parameter country
is not null else I want to get all records in iDs
SQL Query is not working in case of null country parameter. I want my query to be like
-
When country is null
select ea.* from employee ea where ids in (?1)
-
When country is not null
select ea.* from employee ea where ids in (?1) and country =?2
3
Answers
Why you want use native query?
This code works for me.
this is spring-data use @query and spel
or
you can use
EntityManager