Controller属于Presentation层? [英] Controller belongs to the Presentation layer?

查看:52
本文介绍了Controller属于Presentation层?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

听说控制器属于表现层.怎么可能?

I heard that controller belongs to the presentation layer. How is it possible?

我认为:

  • 视图用于演示
  • 模型用于业务逻辑
  • controller 用于控制逻辑

有没有好的链接证明控制器属于表现层?

Is there good link to prove that controller belongs to the presentation layer?

Spring MVC用于表现层":如何只在表现层使用MVC?

"Spring MVC is used for presentation layer": how can we use MVC only in the presentation layer?

推荐答案

表示层包含视图控制器.
您不能将 MVC 架构误认为多层/层架构(尤其是 3 层架构).大多数时候模型/视图/控制器不是 Web 应用程序的主要设计,它只是多层/层架构的一个子集.

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.

看看这个过于简单的方案(你可以在专用的数据访问层中使用 DAO,但这在这篇文章中并不重要):

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 是一个表示框架:它处理控制器和视图.但是为什么 Spring MVC 中的M"呢?正因为与许多其他表示框架一样,它自然地处理模型/实体(M")的表示.这种表示在您的控制器中使用、在您的视图中显示、在您的表单中提交等.这就是该框架被称为 Spring MVC 的原因,即使模型/实体不是表示层的一部分.强>

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.

我认为这是这个框架的好名字,因为它确实是面向MVC"的.实际上,模型/实体的表示可以是:

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 :框架直接处理模型/实体对象
  • indirect :框架处理表单对象或 DTO,其中包含与一个或多个实体相关的信息

Spring 的推荐 是直接使用模型/实体(M")对象:

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.

这就是为什么我说该框架非常面向MVC",与其他框架(例如 Struts)相比,您必须使用不同的表单对象.

That's why I say the framework is very "MVC" oriented, compared to others, like Struts, where you have to use different form objects.

一些有趣的链接:

  • 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

这篇关于Controller属于Presentation层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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