请求MVC和组件MVC之间的区别 [英] Difference between Request MVC and Component MVC
问题描述
在基于请求(动作)的MVC中,单个前端控制器servlet将根据请求URL /参数委派给动作模型。您可以直接使用动作模型中的原始 HttpServletRequest
和 HttpServletResponse
对象。您必须自己编写代码来收集,转换和验证请求参数,并在必要时更新模型值,然后才能调用业务操作。
在基于组件的MVC,单个前端控制器将收集,转换和验证请求参数,并更新模型值本身,以便您只需要自己担心业务操作。控制器需要收集/转换/验证/更新值的方式在一个单独的视图中定义。由于普通HTML是不可能的,因此需要使用特定的标记语言来实现目标。在JSF 2.0的情况下,这是基于XML(XHTML)的。您使用XML来定义UI组件,而UI组件又包含有关控制器如何收集/转换/验证/更新模型值以及生成/呈现必要的HTML表示的信息。
此处应该明确的优点和缺点:通过基于请求的MVC框架,您需要自己编写更多(代码)代码来实现目标。但是,您最终可以对流程和HTML / CSS / JS输出进行更精细的控制。使用基于组件的MVC框架,您不需要自己编写多个代码。但是,您对该过程和HTML / CSS / JS输出的细粒度控制较少。所以如果你想做的不同于标准描述和/或实现提供的 ,那么当你不是在基于组件的MVC框架中时,你将浪费更多的时间精湛的内存和精华。
Manfred Riem(JSF 2.x团队成员和Java EE 8 MVC 1.0规范主管)在Devoxx 14中很好地概述了:
另见:
- JSF需要什么,当CSS可以从CSS ,HTML,JavaScript,jQuery?
- Java Server Faces的主要缺点是什么? 2.0?
- 使用JSF作为Spring MVC的查看技术
- 基于Web的应用程序设计模式
I have heard that JSF is implementing the component based MVC and Spring MVC is implementing the request based MVC. I would like to know what is the exact technical difference between these two types.
In request (action) based MVC, a single front controller servlet will delegate to action models based on request URL/params. You work directly with raw HttpServletRequest
and HttpServletResponse
objects in the action model. You've to write code yourself to gather, convert and validate the request parameters and if necessary update the model values before you can ever invoke the business action.
In component based MVC, a single front controller will gather, convert and validate request parameters and update the model values itself so that you only need to worry about the business action yourself. How the controller needs to gather/convert/validate/update the values is definied in a single place, the view. Since that's not possible with "plain" HTML, a specific markup language is required to achieve the goal. In case of JSF 2.0, that's XML (XHTML) based. You use XML to define UI components which in turn contain information about how the controller should gather/convert/validate/update the model values and generate/render the necessary HTML representation.
Advantages and disadvantages should be clear at this point: With a request based MVC framework you need to write more (boilerplate) code yourself to achieve the goal. However you end up with much more fine grained control over the process and the HTML/CSS/JS output. With a component based MVC framework you don't need to write much code yourself. However you have less fine grained control over the process and the HTML/CSS/JS output. So if you'd like to do things a bit differently than the standard describes and/or the implementation provides, then you'll waste a lot more time in a component based MVC framework when you're not well versed with its ins and outs.
Manfred Riem (JSF 2.x team member and ex Java EE 8 MVC 1.0 spec lead) has outlined it nicely during Devoxx 14:
See also:
- What is the need of JSF, when UI can be achieved from CSS, HTML, JavaScript, jQuery?
- What are the main disadvantages of Java Server Faces 2.0?
- Using JSF as view technology of Spring MVC
- Design Patterns web based applications
这篇关于请求MVC和组件MVC之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!