Spring Data中的查询创建

编程入门 行业动态 更新时间:2024-10-21 03:49:10
本文介绍了Spring Data中的查询创建 - 动态where子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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中的查询创建

本文发布于:2023-10-25 14:00:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1527162.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Spring   Data

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!