I have a case here for a products Table, That needs to be filtered by user input like Category, color, size, price range and many more.
I'm using Spring Data JPA and happy with its derived query from method name and when I'm forced to I just use the @query option for more complex queries like joins and ...
But for the Filter method that I need, I'm afraid I have to write something like this
public interface ProductRepository extends JpaRepository<Product, Long> { //..... other methods Page<Product> findByCategoriesContainingAndSalepriceBetween(List<Category> categories, Float minprice, Float maxprice, PageRequest pagerequest); Page<Product> findByCategoriesContaining(List<Category> categories, PageRequest pagerequest); Page<Product> findByCategoriesContainingAndSizeIn(List<Category> categories,Int[] sizes, PageRequest pagerequest); Page<Product> findByCategoriesContainingAndSizeInAndSalepriceBetween(List<Category> categories,Float minprice, Float maxprice, PageRequest pagerequest);
}
it seems adding some other fields will force me to write so many different combinations
so I've looked at QueryDsl and Specification but they seem so much of extra code, could you put me on the right path??
I would disagree that QueryDSL results in a lot of extra code. Here's some test code I have for QueryDSL:
Repository Definition:
Test Code based on various attributes and combinations thereof: