Spring数据中是否有办法动态形成where子句?
Is there a way in Spring data to dynamically form the where clause?
我想要做的是有一个方法(就像findBy / get方法一样)运行WHERE和AND使用提到的属性为NOT NULL。
What I want to do is have a method (which is like the findBy / get method) which runs a WHERE and AND using the mentioned properties which are NOT NULL.
例如,
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)谢谢。
推荐答案看看JPA规范和谓词,甚至更好的QueryDSL,这两个都得到了Spring数据库的支持。 本文提供了一个示例: spring.io/blog/2011/04/26/advanced-spring-data-jpa-specifications-and-querydsl/
Take a look at JPA Specification and Predicate, and Even better QueryDSL, there both supported by spring data repositories. This article provide an example: spring.io/blog/2011/04/26/advanced-spring-data-jpa-specifications-and-querydsl/
更多推荐
Spring Data中的查询创建
发布评论