Spring的Web应用程序的MVC结构? [英] MVC Structure for Web application in Spring?

查看:115
本文介绍了Spring的Web应用程序的MVC结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Spring MVC开发Web应用程序.早些时候我使用的是控制器层,服务层(业务逻辑),模型层(实体)和DAO(DB)层.

Using Spring MVC to develop a web application. Earlier I was using Controller layer, Service layer(business logic), Model layer(entity) and DAO(DB) layer.

但是有人指出,我应该再介绍两层. dto层,用于从前端和转换层收集数据,转换层将比dto转换为模型(实体)层对象.

But someone pointed out that i should introduce two more layer ie. dto layer for collecting data from front end and transforming layer which will convert than dto into model(entity) layer objects.

现在我正在使用:

  1. 控制器层(它将数据发送到DTO层)
  2. DTO层(它将其数据发送到转换层)
  3. 转换层(用于将dto层对象转换为实体层对象)
  4. 服务层(业务逻辑)
  5. 实体层(将与数据库映射的POJO)
  6. DAO(将使用实体对象存储数据库)

通过这种方式,我们可以使前端和后端数据保持不同.请帮帮我,这对Spring MVC是否合适?

In this way we can keep front end and backend data different. Please help me out, is this a proper structure for Spring MVC ?

推荐答案

但是有人指出,我应该再介绍两层. dto层,用于从前端和转换层收集数据,这些数据将比dto转换为模型(实体)层对象.

But someone pointed out that i should introduce two more layer ie. dto layer for collecting data from front end and transforming layer which will convert than dto into model(entity) layer objects.

不,这是不正确的.您应该只使用必要的图层.

No, it's incorrect. You should use only layers that are necessary.

我以前使用的是控制器层,服务层(业务逻辑),模型层(实体)和DAO(DB)层.

Earlier I was using Controller layer, Service layer(business logic), Model layer(entity) and DAO(DB) layer.

这也是不正确的. MVC是一种模式,没有严格的定义,但是它仅用于称为 view layer 的一层,或称为 presentation layer .模型,视图和控制器所在的位置.还有另一个称为服务层的层,该层是可选的.然后是持久层,在这一层中,您将对对象进行建模并将其保存在数据库或其他地方.简单的Web应用程序不需要更多的层.

This is also incorrect. There's no strict definition of MVC is a pattern, but it's used only on one layer called a view layer, or in other terms presentation layer. Where the model, view, and controller reside. There's another layer called a service layer, which is optional. Then persistence layer, in this layer you model your objects and save them in the database or somewhere else. No more layers are necessary to the simple web application.

关于模型的几句话,它是您要保留或在视图层中用于显示/存储数据的一组类.在这里您可以使用它,因为有人喜欢使用它自己的模型来显示/存储数据,而其他人喜欢使用自己的模型来保存它.这些转换通常是在持久性或服务中,或在两层中完成的.请记住,所有层之间都是松散耦合的,但是您可以将数据bean从一层传输到另一层,然后再传输回去,而不会出现问题.处于分离状态的实体或诸如DTO之类的其他bean是可以在层之间传递和烘焙的此类对象的示例.并且不需要其他层.

A few words about model, it's a set of classes that you want to persist or use in the view layer to show/store the data. Here you can play with it, because someone prefer to use it's own model to show/store the data, and others prefer their own model to persist it. These transformations are usually done in persistence or service, or in both layers. Keep in mind that all layers a loosely coupled to each other, but you can transfer data beans from one layer to another and back without problems. Entities in the detached state or other beans like DTOs are examples of such objects that you can pass and bake between layers. And no additional layers are necessary.

这篇关于Spring的Web应用程序的MVC结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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