SpringMVC a small note (a)

MVC model (Model-View-Controller): a framework of the model will help us develop the code structure, the organization

is more reasonable.

Model (data model), to provide data to show, including data and behavior.

View (view), the model on display.

Controller (Controller) receives a user request to delegate processing model, the model data is processed after it is returned to the view. [Dispatch] role


in the standard MVC, the model can take the initiative to try to update the data (Observer design pattern can be used), but in the Web development model can not take the initiative to the view, it can not take the initiative to update the user interface, because Web access is a request - response model. After a request by the client must take the initiative, the server to return data.


Core components:

1.DispatcherServlet :( front-end controller), sent by the client for filtering, processing logic requests want.

After 2.HandlerMapping :( mapper processor), the DispatcherServlet receives the URL client request, in accordance with certain matching rules, and then forwards the request to the corresponding Controller, the matching rules determined by HandlerMapping.

3.HandlerAdaptor :( processor adapter). Processor Adapter Handler for each object adapted to be executed.
     By HandlerAdapter can support any type of processor as
4.Controller / Hendler :( controller / processor). For processing user requests, and returns the user to view the object after the specified processing is completed.
5.ViewResolver :( view resolver). Handler returns a logical view name, requires a parser capable of converting a logical view of actual physical view.

SpringMVC core framework provides a Servlet objects (DispatcherServlet front controller) receives a request to resolve the server, when the request is to obtain DispatcherServlet, DispatcherServlet mapping relationship needs HandlerMapping objects, the request will be forwarded to the real process can be customer requests controller [controller] to deal with. Controller After processing is complete, return ModelAndView object, which is a combination of model and the view. Found ViewResolver ModelAndView real physical view of the logical view names, ModelAndView use in view of the data model which render.

SpringMVC built in the project:
    1. Building Web item
    2. Import jar package
    Configuration front controller
     (the object is a Servlet), inherited from HttpServlet. Arranged in web.xml
        example:
        <the servlet>
            <the servlet-name> SPRINGMVC </ the servlet-name>
            <the servlet-class> org.springframework.web.servlet.DispatcherServlet </ the servlet-class>
            <Load-ON-Startup> . 1 </ Load-ON-Startup>
             </ the servlet>
        <
          <the servlet-name> SPRINGMVC </ the servlet-name>
          <URL-pattern> *. Action </ URL-pattern>
        </ Mapping the servlet->
    4. Controller write controller
        implement the Controller interface
    5. configure the processor mapper (with default configuration)
        Effects: url name corresponding to the bean and
    6. the adapter processor configuration (with the default configuration)
    7. resolver configuration view (with a default configuration)
        prefixes and suffixes are empty
    8. processor configured
        to prepare good handler / controller configuration in the spring into and allowed to accept spring IoC container management
      <bean name = "/ hello.action"   class = "com.briup.web.controller.HelloWorldController" />
    
intercepts all requests:
        <URL-pattern> / </ url-pattern>
custom intercepts the request:
        . * .html, * CSS ......
solve static resources are intercepted:
        a.Tomcat use of defaultServlet static files
            such as:
        <-Mapping the servlet>
            <the servlet-name> default </ the servlet-name>
            <URL-pattern> * JPG </ URL-pattern>.
        </ Mapping the servlet->
        Features: 1. To configure multiple
              2. write in DispatcherServlet front
              3. High Performance
        two using <mvc: resources>. tag
            example:
                <MVC: mapping Resources = "/ Images / **" LOCATION = "/ Images /" />
                mapping: mapping
        two *, a map representing the specified path URL at all,
        three use. <mvc: default-servlet- handler /> tag
        is added to this tag in the configuration file is spring to
spring provided encoding filter:
        <filter>
        <filter-name> CharacterEncodingFilter </ filter- name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

Guess you like

Origin www.cnblogs.com/JSB-Li/p/11764843.html