控制器属于演示层? [英] Controller belongs to the Presentation layer?
问题描述
我以为:
- 视图用于演示
- 模型用于业务逻辑
- 控制器用于控制逻辑
有没有很好的链接来证明控制器属于表示层?
Spring MVC用于表示层:我们如何才能使用MVC在表达层中?
表示层包含视图 和 控制器。
您不得将MVC架构错误地用于多层/层架构(尤其是3层架构)。大部分时间模型/视图/控制器不是Web应用程序的主要设计,它只是多层/层架构的一个子集。
查看这个过于简单的方案(您可以在专用的数据访问层中使用DAO,但这并不重要):
Spring MVC是一个演示框架:它交易与控制器和视图。但是为什么Spring中的MMVC?正如许多其他演示框架一样,它自然地处理一个模型/实体(M)的表示。这种表示方式是您的控制器中使用的表示形式,在您的视图中显示,以表单形式提交。这就是为什么框架被称为Spring MVC,即使模型/实体不是prensentation层的一部分。 strong>
我认为这是一个很好的名称为这个框架,因为它是真正的MVC导向。实际上,模型/实体的表示可以是:
- direct:框架直接处理模型/实体对象
- indirect:框架处理一个表单对象或DTO,它包含与一个或多个实体相关的信息
Spring的推荐是直接使用模型/实体(M)对象:
可重用的业务代码,不需要重复。使用现有的业务对象作为命令或表单对象,而不是镜像它们来扩展特定的框架基类。
这就是为什么我说框架是非常MVC的,与其他人相比,如Struts,您必须使用不同的表单对象。
一些有趣的链接:
- 多层和MVC架构之间的比较维基百科
- 关于ASP.NET的3层体系结构的这篇博文
- 3层架构的博客图像
- DispatcherServlet章节从Spring的文档
I heard that controller belongs to the presentation layer. How is it possible?
I thought that :
- view is for presentation
- model is for business logic
- controller is for controlling logic
Is there good link to prove that controller belongs to the presentation layer?
"Spring MVC is used for presentation layer": how can we use MVC only in the presentation layer?
The presentation layer contains views and controllers.
You must not mistake an MVC architecture for a multitier/layer architecture (especially a 3-tier architecture). Most of the time Model/View/Controller is not the primary design of a web application, it is just a subset of a multitier/layer architecture.
Take a look at this oversimplified scheme (you could have the DAOs in a dedicated Data Access Layer, but this is not important in this post) :
Spring MVC is a presentation framework : it deals with controllers and views. But why the "M" in Spring MVC ? Just because, as many other presentation framework, it naturally deals with a representation of a model/entity ("M"). This representation is the one used in your controllers, displayed in your views, submitted in your forms, etc. That's why the framework is called Spring MVC, even if the model/entity is not part of the prensentation layer.
I think it is a good name for this Framework, because it is really "MVC" oriented. Indeed the representation of a model/entity can be :
- direct : the framework directly handles the model/entity object
- indirect : the framework handles a form object or DTO, that contains information related to one or multiple entities
Spring's recommendation is to directly use the model/entity ("M") object :
Reusable business code, no need for duplication. Use existing business objects as command or form objects instead of mirroring them to extend a particular framework base class.
That's why I say the framework is very "MVC" oriented, compared to others, like Struts, where you have to use different form objects.
Some interesting links :
- Comparison between Multitier and MVC architecture, from Wikipedia
- This blog post about 3-tier architecture in ASP.NET
- This blog image of a 3-tier architecture
- DispatcherServlet chapter from Spring's documentation
这篇关于控制器属于演示层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!