Spring Framework 中的 DAO、DTO 和 Service 层是什么? [英] What are the DAO, DTO and Service layers in Spring Framework?

查看:27
本文介绍了Spring Framework 中的 DAO、DTO 和 Service 层是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 spring 和 hibernate 编写 RESTful 服务.我在互联网上阅读了很多资源,但他们并没有澄清我的疑虑.请详细解释一下spring框架中什么是DAODTOService层?以及为什么在春季需要使用这些层来开发 RESTfull API 服务.

I am writing RESTful services using spring and hibernate. I read many resource in internet, but they did not clarify my doubts. Please explain me in details what are DAO, DTO and Service layers in spring framework? And why usage of these layers is required in spring to develop RESTfull API services.

推荐答案

首先,这些概念是平台不可知的,并不是 Spring Framework 或任何其他框架所独有的.

First off, these concepts are Platform Agnostic and are not exclusive to Spring Framework or any other framework, for that matter.

>


数据传输对象

DTO 是一个在进程间携带数据的对象.当您使用远程接口时,每次调用都是昂贵的.因此,您需要减少调用次数.解决方案是创建一个数据传输对象,它可以保存调用的所有数据.它需要可序列化才能跨越连接.通常在服务器端使用汇编器在 DTO 和任何域对象之间传输数据.经常很少不仅仅是一堆字段以及它们的 getter 和 setter.

DTO is an object that carries data between processes. When you're working with a remote interface, each call it is expensive. As a result you need to reduce the number of calls. The solution is to create a Data Transfer Object that can hold all the data for the call. It needs to be serializable to go across the connection. Usually an assembler is used on the server side to transfer data between the DTO and any domain objects. It's often little more than a bunch of fields and the getters and setters for them.

一个数据访问对象抽象并封装了所有对数据源.DAO 管理与数据源的连接获取和存储数据.

A Data Access Object abstracts and encapsulates all access to the data source. The DAO manages the connection with the data source to obtain and store data.

DAO 实现了处理数据源所需的访问机制.数据源可以是像 RDBMS 这样的持久存储,也可以是通过 RESTSOAP 访问的业务服务.

The DAO implements the access mechanism required to work with the data source. The data source could be a persistent store like an RDBMS, or a business service accessed via REST or SOAP.

DAOService 对象的底层数据访问实现抽象为启用对数据源的透明访问.Service 也委托数据加载和存储操作到 DAO.

The DAO abstracts the underlying data access implementation for the Service objects to enable transparent access to the data source. The Service also delegates data load and store operations to the DAO.

Service 对象正在执行应用程序需要为您正在使用的域做.它涉及基于输入的计算和存储的数据,验证来自演示文稿的任何数据,并弄清楚究竟是什么数据要分派的源逻辑,具体取决于从演示文稿收到的命令.

Service objects are doing the work that the application needs to do for the domain you're working with. It involves calculations based on inputs and stored data, validation of any data that comes in from the presentation, and figuring out exactly what data source logic to dispatch, depending on commands received from the presentation.

Service Layer 定义了应用程序的边界及其可用操作集连接客户端层的角度.它封装了应用程序的业务逻辑,控制在其运营实施过程中进行交易和协调响应.

A Service Layer defines an application's boundary and its set of available operations from the perspective of interfacing client layers. It encapsulates the application's business logic, controlling transactions and coordinating responses in the implementation of its operations.

Martin Fowler 有一本关于常见应用程序架构模式的好书,名为企业应用架构模式.还有,核心 J2EE 模式值得一看.

Martin Fowler has a great book on common Application Architecture Patterns named Patterns of Enterprise Application Architecture. There is also, Core J2EE Patterns that worth looking at.

这篇关于Spring Framework 中的 DAO、DTO 和 Service 层是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆