Spring MVC and MVC model acquaintance

Overview of
traditional Model1 and Model2
in Model1 mode, the entire Web application is almost entirely composed by the JSP page, accept and process user requests, and responds directly to the request processing; JSP View and Controller who is also the two roles, will control logic and presentation logic blend together.
Disadvantages:
Low 1 code reusability.
2. Add the application extensions and difficult to maintain.

Model2 is based on the design pattern MVC architecture embodied as follows: MVC is the idea of an application into three basic parts, the model (the Model), view (View), the controller (the Controller), at least three components coupling work, thereby improving the scalability and maintainability of the application. 1. Model (the Model): the JavaBean 2. View (View): JSP page 3. Controller (Controller): Servlet
MVC hierarchical design



MVC model makes Model2 has a component-based features, more suitable for developing large-scale applications (but increases the complexity of development).
MVC advantage of
MVC is not the Java language and Web application-specific design, it is all object-oriented programming language should comply with the specification.
In the classic MVC model, the event processed by the controller, the controller changes the view of the model or type of event, and vice versa.
MVC features:
1. Multiple views may correspond to a model. According to the MVC design pattern model corresponding to a plurality of views, copying and maintenance of code code can be reduced. Once the model changes, but also easy to maintain.
2. Model data returned by the display logic. Data model can be applied to any display technology.
3. The application is divided into three levels, reducing the coupling between the layers, a scalable application.
Concept 4. The control layer is also very effective, since the combination with different models and different views, different request completion. Accordingly, the control layer may comprise a conceptual permissions requested by the user.
5.MVC more in line with the spirit of software engineering management. Their duties different layers, each layer having components of the same features, which facilitate the generation management program code of engineering tools and methods.
Note: There is a classic MVC MVC thought and thought Web applications are some differences, mainly due to Web application is a request / response mode. If the user does not request the application, you can not take the initiative to update their view.
MVC the Spring
the Spring framework for building Web applications provides a full-featured MVC module: Spring MVC.
Spring MVC provides a DispatcherServlet to distribute the request as a front-end controller, while providing a flexible configuration handler mappings, view resolution, locale and theme resolution, and support for file uploads. Spring MVC view that contains a variety of techniques to separate the role of controller, model object, dispatcher and handler objects, making them easier to customize.
Spring MVC Features:
1. Has great flexibility, non-invasive, configurability.
2. To provide a front-end controller DispatcherServlet, no additional development controller object.
3. A clear division includes a controller, validator, command object, the object model, like handler mapping view resolver, each function is realized by a specialized object is responsible for completion.
4. The user input can be automatically bound, and the correct data type conversion.
5. Use a name / worthy Map object to achieve a more flexible model for data transmission.
6. Built-common check, you can check user input, if the check is not passed, then redirected back to the input form. Optional input validation, programmatically and declaratively support.
7. Support internationalization, support for multiple languages based on the user display area, and an international configuration is very simple.
8. Support multiple view technologies.
9. Provide a simple yet powerful JSP tag library, support for data binding.
Spring MVC uses
Spring MVC's DispatcherServlet is a Servlet, inherited from HTTPServlet, so you need to configure the web.xml file of the Web application in use:

  . 1 <the servlet>
   2    <-! Name of the Servlet ->
   . 3    <the servlet-name> SpringMVC </ the servlet-name>
   . 4    <-! Java class corresponding to the Servlet ->
   . 5    <servlet- class > org.springframework .web.servlet.DispatcherServlet </ servlet- class >
   . 6    <-! Servlet current parameters ->
   . 7    <the init-param>
   . 8      <-! Servlet parameter name ->
   . 9      <param-name> the contextConfigLocation < / param-name>
 10      <- Servlet parameter values:! Spring MVC profile path ->
 . 11      <param-value> CLASSPATH: SpringMVC-the config.xml </ param-value>
 12   </init-param>
 13   <! - Load Web application startup immediately Servlet ->
 14    <the Load-ON-the Startup> 1 </ the Load-ON-the Startup>
 15 </ the servlet>
 16 <! - Servlet mapping declarations ->
 17 < -Mapping the servlet>
 18 is    <-! name of the Servlet corresponding to the request ->
 . 19    <the servlet-name> SpringMVC </ the servlet-name>
 20 is    <-! request listening all the current domain ->
 21 is    <URL-pattern > / </ URL-pattern>
 22 is </ Mapping the servlet->

Profiles of each strip configuration meaning see note content, meaning the entire contents of the file: Configure a DispatcherServlet, the DispatcherServlet load immediately when the Web application starts, DispatcherServlet when loading need a Spring MVC configuration file, the default will be to use Configuration Find [servlet-name] -servlet.xml file under WEB-INF directory of the program directory, that is, in the above configuration is to find /WEB-INF/springmvc-servlet.xml.
The above configuration is the configuration file named springmvc-config.xml, and use the init-param element parameters have been configured, it indicates DispatcherServlet looks classpath of the application: springmvc-config.xml file as a configuration file, and parses the configuration file WebApplicationContext create a content container object (context).
WebApplicationContext inherits from ApplicationContext container, it is different initialization method and ApplicationContext, because WebApplicationContext need ServletContext instance, you must have a premise Web container to complete Spring Web application context start work.
MVC pattern, and the frame Spring MVC DispatcherServlet previously recorded here, the back Spring MVC continued usage records.

Guess you like

Origin www.cnblogs.com/Dcl-Snow/p/11444650.html