MVC ::什么是模型? [英] MVC :: What is a model?

查看:62
本文介绍了MVC ::什么是模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在必须就模型做出决定.

我知道模型是您用来进行所有数据库操作的

但是模型是否仅限于此?

这是我的意思.

它们仅用于数据库交互吗? 还是它们用于所有外部数据操作(例如来自外部API的数据等)?

解决方案

例如,在Django中,模型是一个类,该类映射到数据关系(表)并可能桥接表(例如,对于多对多关系). /p>

同一类可以具有用于对相应数据进行操作的方法,可以有其他类不是通过自身定义模型,而是访问和过滤数据的方法.

但是MVC中的术语模型确实适用于描述数据结构以及通常访问它们的方法.

这些框架可能在某种程度上扭曲了抽象术语.例如,Django所谓的视图实际上是控制器功能,而定义表示形式的实体称为模板,而不是视图.

I am at a point where I must make a decision about models.

I am aware that models are what you use to do all your database manipulation.

But are models restricted to this?

By this I mean.

Are they meant only for database interaction, Or are they meant for all external data manipulation (e.g. data from external APIs etc)?

解决方案

For example, in Django, model is a class that maps to the data relation (table) and potentially bridge tables (e.g. for many to many relations).

The same class can have methods for the manipulations on the corresponding data, there could be additional classes that are not defining models by themselves, but the methods of accessing and filtering the data.

But term model in MVC does apply to describing data structures and the methods to access them in general.

The frameworks may be somewhat bending the abstract terminology. For example what Django calls views are actually controller functions, and the entities defining the presentation are called templates, instead of views.

这篇关于MVC ::什么是模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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