I tried to create dynamic query using JPA specification, but I'm not sure whether I understood the JPA specification properly. I was using https://www.baeldung.com/spring-data-criteria-queries to write the code. The case is, I got some paramters that are optionals, so first I've written all etc alone. like this (from above site):
while scrolling down the site I could read about JPA specifiaction and it looked much more better, because within each parameters I got next if using above solution.
Using JPA specification the code looks like this for now:
As you can see code looks much more better, I got rid of boiler plate, but the problem is, just those advertisements are returned that meet all requirements so it has category/city/proper title.
If I got
and if I put only Warsaw I want it to be returned, if I put only random (as title) I want it to be returned etc etc, for now if I put Warsaw, random (as title), MUSIC Could you tell me how to do it?
PS: The code I write is kotlin, but it is very similiar to java so you can propose solution in java if you want.
Thanks a lot for help!
I changed to
and it works, but the question is, how to make to return all the advertisements if no parameters where passed.