mvc中的mvc分别指什么

by Adam Wattis

通过亚当·沃蒂斯(Adam Wattis)

什么是MVC,它像三明治店吗? (What is MVC, and how is it like a sandwich shop?)

In today’s Internet, websites tend to be interactive, dynamic, and serve some sort of function. They can be more than a static HTML and CSS page. Here’s where the Model View Controller (MVC) architectural pattern comes in.

在当今的Internet中,网站往往是交互式的,动态的,并具有某种功能。 它们不仅可以是静态HTML和CSS页面。 这就是模型视图控制器 (MVC)架构模式的用武之地。

User interaction enables use cases which would be impossible with only a statically loaded page. This is why, in modern web development, it is important to understand how dynamic pages are created. Perhaps the key to this is familiarity with the MVC architectural pattern.

通过用户交互,可以实现仅静态加载的页面无法实现的用例。 这就是为什么在现代Web开发中,重要的是要了解如何创建动态页面。 也许关键在于对MVC架构模式的熟悉。

If you are a beginner at web development, words such as “architectural pattern” may sound dauntingly complex and abstract. But the general idea behind MVC is actually very intuitive. I will do my best to explain it in such a way in this article.

如果您是Web开发的初学者,那么诸如“建筑模式”之类的词听起来可能令人生畏,复杂而抽象。 但是MVC背后的总体思路实际上是非常直观的。 我将尽力在本文中以这种方式进行解释。

了解MVC重要吗? (Is MVC important to understand?)

In my mind, the answer to this question is yes.

在我看来,这个问题的答案是肯定的。

MVC is important to understand because it is the basic structure which most web applications are built on. The same is also true for mobile apps and desktop programs.

了解MVC非常重要,因为它是大多数Web应用程序所基于的基本结构。 移动应用程序和桌面程序也是如此。

There are many variations around the basic idea of MVC. The initial conceptwas created around 1978 at Xerox PARC by Trygve Reenskaug. It was intended to help an end user manipulate and control an underlying computer system in a more visual and intuitive way.

关于MVC的基本概念有很多变体。 最初的概念是1978年左右由Trygve Reenskaug在施乐PARC创建的。 它旨在帮助最终用户以更直观和直观的方式来操纵和控制底层计算机系统。

MVC achieves this though letting a user interact with a User Interface. This allows for manipulation and control over the system.

MVC通过允许用户与用户界面进行交互来实现此目的。 这允许对系统进行操纵和控制。

高层次的概念 (The high-level concept)

Without using any fancy words, I will now explain the basic idea behind MVC through a simple use case.

现在,不用花哨的词,我将通过一个简单的用例来解释MVC背后的基本思想。

Imagine you are in a sandwich shop. You walk up to the counter and look at the menu.

想象你在一家三明治店里。 您走到柜台,看看菜单。

You decide you want the turkey sandwich (in fact, you can already imagine biting into it). So you tell the clerk your order.

您决定要土耳其三明治(实际上,您已经可以想象一下要咬它)。 所以你告诉店员你的订单。

The clerk knows exactly what you want when you order the turkey sandwich. He turns around to the sandwich-making station, and tells the people there what they need to know to fulfill your order.

当您订购火鸡肉三明治时,店员会确切地知道您想要什么。 他转身到三明治制作站,并告诉那里的人们要完成您的订单需要了解什么。

The sandwich-making team has many resources at their disposal. Ham, turkey, tuna, salad and cheese can all go in the sandwiches. They take the ingredients required for your order, and assemble them into the turkey sandwich that you have ordered.

三明治制作团队有很多资源可供使用。 火腿,火鸡,金枪鱼,沙拉和奶酪都可以放入三明治中。 他们采用您订购所需的食材,然后将它们组装到您订购的火鸡肉三明治中。

After the sandwich is complete, it is handed over to you. You now have the turkey sandwich you wanted.

三明治完成后,将其交给您。 现在,您有了想要的火鸡三明治。

一个解释 (An explanation)

In this previous example, there were three separate and distinct objects which all represent one part in our MVC:

在前面的示例中,有三个单独且不同的对象,它们全部代表我们的MVC中的一部分:

  • The sandwich-making station (Model)三明治制作台(型号)
  • The finished sandwich you received in the end (View)您最终收到的成品三明治(查看)
  • The clerk (Controller)业务员(控制器)

When you ordered your sandwich, you had a distinct idea of what you expected the end result to be: a turkey sandwich (view).

订购三明治时,您对预期的最终结果有不同的认识:火鸡三明治( 视图 )。

This is the same as when you’re on a website. For example, on Facebook you can press the ‘Friends’ button to see a list of your friends. You would expect your friend list to appear, and can already visualize it in your mind.

这与您在网站上的情况相同。 例如,在Facebook上,您可以按“朋友”按钮以查看您的朋友列表。 您希望您的朋友列表出现,并且可以在您的脑海中将其可视化。

When you press the ‘Friends’ button, you make a request to Facebook’s servers. The request is to serve you with your friends list, just like you requested your sandwich to the clerk (controller).

当您按下“朋友”按钮时,您向Facebook的服务器发出请求。 该请求是为你和你的朋友列表,就像你要求你的三明治店员( 控制器 )。

Your request arrives at Facebook’s servers. It hits their controller, which tries to resolve it. It then grabs all your friends from a database, just like the sandwich-maker (model) grabs all the ingredients.

您的请求到达了Facebook的服务器。 它命中了他们的控制器,试图解决它。 然后,它从数据库中获取所有朋友,就像三明治制造商( 模型 )获取所有成分一样。

These resources (your friends list data) is assembled into a response. This is similar to how the sandwich-maker assembled all the ingredients into a finished sandwich (view).

这些资源(您的朋友列出数据)被组合成一个响应。 这类似于三明治制造商将所有配料组装成成品三明治的方式( 视图 )。

This friends list is then sent to you for consumption, like the sandwich was in the end of your order.

然后,此朋友列表会发送给您供您消费,就像三明治在您的订单末尾一样。

摘要 (Summary)

The clerk is the controller:

业务员是控制者:

  • He knows all the possible combinations of sandwiches you can order他知道您可以订购的所有可能的三明治组合
  • He gathers your info and sends an order back to be resolved他收集了您的信息并发回订单以解决

The sandwich-makers are the models:

三明治机是以下型号:

  • They know what items are needed to assemble your finished sandwich他们知道组装成品三明治需要哪些物品

The sandwich is the view:

三明治是这样的:

  • It is the ‘thing’ the end user finally receives这是最终用户最终获得的“东西”

使用网络框架 (Using a web framework)

Controller:The controller handles incoming requests. In a web framework, this would be a declaration of specific URLs that map to specific functionality that composes your request.

控制器:控制器处理传入的请求。 在Web框架中,这是对特定URL的声明,这些URL映射到构成您的请求的特定功能。

Example URLswebsite.com/profile/ --> returns your profilewebsite.com/friends/ --> returns list of friendswebsite.com/friend={userName}/ --> returns specific friend

Model:This is what your data looks like on the back end.

模型:这就是您的数据在后端的外观。

User:- userName- firstName- lastName- friends

View:This is the HTML template that is returned after your request is resolved. If the request is successful, you should get a page with your friends. Otherwise, you might get a 404 ‘Not found’ page.

视图:这是在您的请求得到解决后返回HTML模板。 如果请求成功,您应该和您的朋友一起获得一个页面。 否则,您可能会看到404“未找到”页面。

<ul>  <li>Friend 1: {friendList[0].userName}</li>  <li>Friend 2: {friendList[1].userName}</li>  <li>Friend 3: {friendList[2].userName}</li>  ...</ul>

结论 (Conclusion)

When interacting with a system, you are usually able to Create, Retreive, Update and Delete objects in the underlying database. This is often abbreviated to “CRUD.” Here, we have looked at retrieving data.

当与系统交互,则通常能够至C reate,R etreive,U PDATE和在底层数据库d elete对象。 这通常缩写为“ CRUD” 。 在这里,我们已经研究了检索数据。

I did not explain here how a user can modify the data in the database (the C, U and D in CRUD). Usually, you are able to add, update and delete things on a website.

我在这里没有解释用户如何修改数据库中的数据( CRUD中CUD )。 通常,您可以在网站上添加,更新和删除内容。

The functionality for this is pretty much the same as explained above. The difference is, your data is attached to your request to the controller.

其功能与上面说明的几乎相同。 区别在于,您的数据将附加到您对控制器的请求中。

I hope that you now have a clearer understanding of what MVC architecture is and how it might work.

我希望您现在对MVC架构及其工作原理有更清晰的了解。

If you thought this explanation was helpful, or have any questions or thought about how to improve this article, please feel free to comment!

如果您认为此说明有用,或者对如何改进本文有任何疑问或想法,请随时发表评论!

翻译自: https://www.freecodecamp.org/news/simplified-explanation-to-mvc-5d307796df30/

mvc中的mvc分别指什么

mvc中的mvc分别指什么_什么是MVC,它像三明治店吗?相关推荐

  1. spring mvc中两种异常的处理手法

    spring mvc中两种异常的处理手法 在spring mvc中,对异常的处理,可以小结有如下两类写法: 1 <bean id="exceptionResolver" cl ...

  2. Spring MVC中@RequestParam和@PathVariable批注之间的区别?

    Spring MVC框架是在Java世界中开发Web应用程序最流行的框架之一,它还提供了一些有用的注释,可以从传入的请求中提取数据并将请求映射到控制器,例如@ RequestMapping,@ Req ...

  3. MVC中controller有什么作用

    一:在MVC中controller可以决定显示哪一个view 二:MVC负责定义和调用Model 三:接受请求时响应数据给页面

  4. mvc中嵌入ssrs报表_如何在SSRS报表中过滤多维OLAP多维数据集

    mvc中嵌入ssrs报表 Ever since the early days of my career, SQL Server Reporting Services (SSRS) has been o ...

  5. java中mvc事务_java核心技术第五篇之事务和MVC模式

    第一部分:事务 1.事务的简介: 1.1 在一组操作中(比如增加操作,修改操作),只有增加和修改操作都成功之后,这两个操作才能真正的成功. ,如果这两个操作中,有一个失败了,这两个操作都失败了. 1. ...

  6. MVC 中的 ViewModel

    此文章总结自:http://rachelappel.com/use-viewmodels-to-manage-data-amp-organize-code-in-asp.net-mvc-applica ...

  7. 通过源代码研究ASP.NET MVC中的Controller和View(二)

    通过源代码研究ASP.NET MVC中的Controller和View(一) 在开始之前,先来温习下上一篇文章中的结论(推论): IView是所有HTML视图的抽象 ActionResult是Cont ...

  8. 在Asp.Net MVC中实现RequiredIf标签对Model中的属性进行验证

    在Asp.Net MVC中可以用继承ValidationAttribute的方式,自定制实现RequiredIf标签对Model中的属性进行验证 具体场景为:某一属性是否允许为null的验证,要根据另 ...

  9. Spring MVC中处理Request和Response的策略

    前沿技术早知道,弯道超车有希望 积累超车资本,从关注DD开始 作者:码农小胖哥, 图文编辑:xj 来源:https://mp.weixin.qq.com/s/3eFygsiVl8dC2nRy8_8n5 ...

最新文章

  1. Spring Framework(框架)整体架构
  2. 一般控制矩阵转能观标准型
  3. centos 7上ambari安装试用
  4. 计算机审计的概念的论文,论文:浅谈计算机审计中的数据分析
  5. 百度盘搜失效?这款网盘搜索神器万万别错过!
  6. Ajax学习笔记-get请求参数-3
  7. 【Elasticsearch】高亮查询 highlighting (一)
  8. 2016最新微信公众号运营必备网址大全
  9. 计算机快速启动BIOS,bios设置快速启动
  10. 一、Matlab图像处理入门
  11. word文档字不靠边_Word打印字体靠右怎么办
  12. 压缩或解压文件出现循环冗余检查的解决办法
  13. wirehark数据分析与取证flag.pcap
  14. 今日早报 每日精选12条新闻简报 每天一分钟 知晓天下事 8月13日
  15. 在线 像素画 工具 PX-Art
  16. 2022-2028全球与中国流量变现平台市场现状及未来发展趋势
  17. jmu-python-生日悖论
  18. 实验输出菱形图案 (5 分)
  19. 论文阅读:CVPR2022 Rethinking Minimal Sufficient Representation in Contrastive Learning
  20. MATLAB 2020a 安装许可证错误问题 licensing error:-8523

热门文章

  1. 办公自动化-ppt的创建实操-各个对象的理解-0223
  2. django-模型类的修改-外键
  3. js高级程序设计 - 温故而知新
  4. 从Softmax回归到Logistic回归
  5. [CentOS7] - CentOS7设置开机启动
  6. 基于最大最小距离的分类数目上限K确定的聚类方法
  7. 学习hashtable,处理“海量”数据
  8. 纠结做电气自动化呢还是编程好。。。
  9. 隆重推荐一本虚拟化方面的重量级图书
  10. Serverless实战 —— 使用 Wintersmith + Serverless Framework 快速创建个人站点