Spring JPA查询创建 - 使用By与谓词 [英] Spring JPA Query Creation - Using By with a Predicate
本文介绍了Spring JPA查询创建 - 使用By与谓词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个使用默认条件和动态谓词的Spring Data JPA查询。
I would like to create a Spring Data JPA query that uses a default criterion and a dynamic predicate.
例如使用Customer实体:
For example using Customer entity:
findByFirstnameIn(List< String> names,Predicate谓词);
另一个解决方案是使用do
Another solution would be to use do
findAll(predicate.and(customer.firstname.in(names)))
但是我我想避免这一额外的代码行。
but I would like to avoid this additional line of code.
推荐答案
你的第二种方法是正确的方法。有一个类似的功能请求,您可能需要关注 https://jira.spring。 io / browse / DATAJPA-1189
Your second approach is the correct way to do it. There is a similar feature request you might want to keep an eye on https://jira.spring.io/browse/DATAJPA-1189
这篇关于Spring JPA查询创建 - 使用By与谓词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文