java 有没有好的通用 JPA DAO 实现?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11058972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 03:37:46  来源:igfitidea点击:

Is there any good generic JPA DAO implemenation?

javajpadao

提问by hoymkot

According this article, generic JPA DAO(Data Access Object) is a pretty nice pattern.

根据这篇文章,通用 JPA DAO(数据访问对象)是一个非常好的模式。

Is there any good implementation?

有什么好的实现吗?

回答by Francisco Spaeth

You could take a look into the Spring Data JPA.

您可以查看Spring Data JPA

A few new concepts were introduced into Spring Data JPA, for instance the Query creation based on the method name, so you can declare a method like findById(String id)and the "generic" implementation will interpret the method's name and execute something like select Entity from Entity where id = 'given string'

Spring Data JPA 中引入了一些新概念,例如基于方法名称的查询创建,因此您可以声明一个方法findById(String id),“通用”实现将解释方法的名称并执行类似的操作select Entity from Entity where id = 'given string'

Methods like findByNameAndLastName(String name, String lastName)or even findByNameOrInternalId(String name, int internalId)are supported too.

也支持像findByNameAndLastName(String name, String lastName)甚至这样的方法findByNameOrInternalId(String name, int internalId)

回答by Biju Kunjummen

Just wanted to mention a couple more generic dao implementations for JPA:

只想提一下 JPA 的几个更通用的 dao 实现:

回答by lujop

Querydslsupports JPA and has an extensive support for building complex predicates for queries.

Querydsl支持 JPA,并广泛支持构建复杂的查询谓词。

It doesn't support updates and inserts but you can use Spring Data for that, as Querydsl also integrates with Spring repositories.

它不支持更新和插入,但您可以使用 Spring Data,因为 Querydsl 还与 Spring 存储库集成。