什么是MVC模式中的模型 [英] what is Model in MVC pattern

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

问题描述

我正在使用MVC模式创建应用程序.为此,我正在考虑将jsps,控制器作为servlet,将模型作为DAO对象.我是否怀疑将DAO对象视为模型是对还是错?

I am creating an application were I am using MVC pattern.For this I am considering my view as jsps,controller as servlets and model as DAO objects.I have a doubt that me considering DAO objects as Model is right or wrong?

推荐答案

MVC中的模型是业务逻辑所在的地方.

A model in MVC is where the business logic lives.

sun Java EE模式定义中,我们看到了DAO封装持久性机制,并由业务对象使用.因此,我认为DAO本质上没有任何业务逻辑.

Looking at the sun Java EE pattern definitions we see that DAOs encapsulate persistence mechanisms and are used by a Business Object. I don't therefore see DAOs as natuarally having any business logic.

在简单的系统中,一些数据库表或在其中实现了业务逻辑的那些表 数据库(存储过程,参照完整性检查,触发器),则DAO实际上是Business Logic的基础,因此它们看起来很像Model.因此,在一些介绍性材料中,您可能会看到DAO几乎是Model的唯一Java表达式.

In simple systems, a few database tables, or those where the business logic is implemented in the database (stored procedures, referential integrity checks, triggers) then the DAO is effectively a facade in front of Business Logic, so they pretty much look like the Model. So in some introductory material you may see the DAO as pretty much the only Java expression of the Model.

当我们选择用Java实现业务逻辑时,它将位于DAO之上的一层中,例如使用DAO的Session Bean,在我看来,是Session Bean或等效模型即Model.

When we choose to implement our business logic in Java, it would lie in a layer above the DAO, in for example Session Beans, which use the DAOs, and in my mind it's the Session Bean or equivalent which is the Model.

所以问问自己:业务逻辑在哪里?那才是真正的模型.

So ask yourself: where is the business logic? That's where the Model really is.

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

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