Creating a query in Spring Data - dynamic where where

Is there a way in Spring for dynamically generating where clauses?

What I want to do is to have a method (which is similar to the findBy / get method) that runs WHERE and AND, using the specified properties that are not NULL.

For example,

Consider the object Person [firstName, lastName, age, gender]

Our method looks something like this.

findBy_IfNotNullFirstName_AndIfNotNullLastName_AndIfNotNullAge_AndIfNotNullGender(String firstName, String lastName, Integer age, String gender)

Thanks.

+4
source share
1 answer

Take a look at the JPA spec and predicate, and better yet QueryDSL, where both are supported by spring data repositories. An example is provided in this article: http://spring.io/blog/2011/04/26/advanced-spring-data-jpa-specifications-and-querydsl/

+5
source

Source: https://habr.com/ru/post/1524715/


All Articles