简体   繁体   English

Spring Boot存储库中的API与DAO

[英]API in Spring Boot Repository vs DAO

I'm trying to design an rest API in spring boot and what to ask about a few design decisions. 我正在尝试在Spring Boot中设计一个Rest API,以及有关一些设计决策的问题。 I am completely confused by the whole difference between DAO vs Repository pattern/design. 我对DAO与存储库模式/设计之间的整体差异感到完全困惑。 After hours of reading I still don't really understand the difference between the two or which one is preferred standard for designing API's that make backend connections. 经过数小时的阅读,我仍然不太了解两者之间的区别,或者是设计用于进行后端连接的API的首选标准。

Here's a simply UML diagram to highlight the high level view of the api: 这是一个简单的UML图,以突出显示api的高级视图: 在此处输入图片说明

This is how I understand a good architecture of an API. 这就是我理解API的良好体系结构的方式。 But then I came across this article using repository pattern instead of dao with a specification design. 但是后来我遇到了使用存储库模式而不是使用规范设计的dao的本文 I don't understand why a dao interface can't just have a query function? 我不明白为什么dao接口不能只具有query功能? Does that break the idea of what a DAO is or something? 这是否打破了DAO是什么的概念?

My question is: what's the best standard to use in today's day in developing an API in Spring Boot and Java 8 我的问题是:在Spring Boot和Java 8中开发API时,今天使用的最佳标准是什么?

If I understood correctly your question, the whole point of using Spring Service/Repository is to separate the business logic from the Controller to the Service class, and the only thing the Repository will do is DB operations, and you will inject it in your Service. 如果我正确理解了您的问题,那么使用Spring Service / Repository的全部目的就是将业务逻辑从Controller分离到Service类,并且Repository唯一要做的就是数据库操作,并将其注入到Service中。 There is no difference between DAO (assuming your DAO is a bunch of code using JPA) and Repository, but with Spring Repository you can use Query Methods, which is awesome! DAO(假设您的DAO是使用JPA的一堆代码)和Repository之间没有区别,但是使用Spring Repository,您可以使用Query Methods,这很棒!

Any suggestion, feel free! 任何建议,请放心!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 @Repository 和 @Autowired 如何在 spring boot Dao 和 Service Layer 中工作? - How @Repository and @Autowired work in spring boot Dao and Service Layer? @Repository dao 中的Spring @PostConstruct 和扩展dao 的@Service - Spring @PostConstruct in @Repository dao and @Service that extends dao Spring DAO存储库异常处理 - Spring DAO Repository exception handling Spring Boot测试API和存储库的多个类 - Spring boot Test multiple classes for API and repository 使用JPA在spring boot中实现DAO - implement DAO in spring boot with JPA spring boot jooq dao 麻烦 - Spring boot jooq dao trouble 使用 @Repository 注释 Dao 类时,Spring Boot 2.1 和 Hibernate 5.3 SessionFactory 未自动装配 - Spring boot 2.1 and Hibernate 5.3 SessionFactory not Autowired when annotating the Dao classes with @Repository 使用带有spring Boot的Dao设计模式,而不是使用spring data jpa提供的存储库设计模式,这是个好主意吗? - Is it good idea to use the Dao design pattern with spring Boot, instead of using repository design pattern provided by spring data jpa? 如何在Spring中使用SQLErrorCodeSQLExceptionTranslator和DAO类与@Repository? - How to use SQLErrorCodeSQLExceptionTranslator and DAO class with @Repository in Spring? 找不到 Spring Boot 存储库 - Spring boot repository not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM