Why is Spring MVC so called, when it is not an MVC framework? [closed]
MVC
describes when the Observer
pattern is used to allow a model to notify the views about changes.
This is not how Spring MVC works.
Spring MVC is a Model2 framework because it doesn't notify the views from the model - the controller simply passes the model data to the views and performs the html generation.
So why is it called "Spring MVC"?
Observers are not necessary in MVC--how the view gets updated is implementation-specific. A controller can just tell the view to render itself, or the view can request a new rendering, which is what happens in almost all web-oriented MVC frameworks.
That said, while most web-oriented MVC frameworks are an interpretation of the original idea of MVC, they're still pretty MVC since they have the separation of components, and operate as a synchronous version of it.
MVC is a design pattern in which there's a view, a model and a controller. Concerning how the view updates itself on model changes, there's no particula statement saying that there should be an Observer patter there from view to model. Having the view actively re-interrogate the model in order to update itself is in accordance with the MVC spec.
Model2 is one implementation of the MVC design. This is something released by the Java EE guys (as well as Model1 which is non MVC compliant). In short, while Model one said you only had a separation between model on the one side (the beans), and view plus controller on the other (both represented by JSP pages), in the Model2 paradigm you have JSP as the view, beans as the model and servlets as the controller.
Spring-MVC is called that and not Spring-Model2 becauese model2 is something related to specific Java EE components such as servlets, JSPs and beans, while Spring-MVC encompasses more than that: the controllers are not servlets, the view can be something else besides JSP, etc.
精彩评论