Equivalent of criteria in spring-data-jpa

Youssef picture Youssef · Jun 30, 2014 · Viewed 16.2k times · Source

I was using hibernate but i heard that spring-data-jpa is the best so i try it and i'm satisfy with it until i face this issue.

I have a search form in my jsp with many criteria and the user can choose whatever he want.

So what is the equivalent of this request in spring-data-jpa

if(startDate!=null){
    criteria.add(Expression.ge("date",startDate));
}
if(endDate!=null){
    criteria.add(Expression.le("date",endDate));
}
if(volume!=null){
    criteria.add(Expression.ge("volume",volume));
}
if ....

Answer

Abhishek picture Abhishek · Jun 30, 2014

It's QueryDSL. Here's a blog post on how to use it with Spring Data.