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

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

问题描述

我现在必须对模型做出决定.我知道模型是您用来进行所有数据库操作的工具.但是模型是否仅限于此?

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?

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

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

推荐答案

例如,在 Django 中,模型是映射到数据关系(表)和潜在桥接表(例如,多对多关系)的类.

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.

但是 MVC 中的术语模型确实适用于描述数据结构和访问它们的一般方法.

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

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

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天全站免登陆