SpringMVC learning framework (a): a preliminary understanding

Introduction: First, we need to understand before learning what is MVC pattern SpringMVC

MVC full name is Model View Controller, is a model (model) - view (view) - abbreviation controller (controller) is a software design model. It is a service logic, and data interface display separation method to organize the code, the number of business logic to gather a member which, at the same time the need to improve and customization interfaces and user interaction does not need to rewrite the business logic , to reduce coding time.

MVC initially present in the desktop program, M is a business model, V refers to the user interface, C is the controller. (The following is a simplified flow diagram of personal understanding)

 

 The flowchart SpringMVC

 

A detailed understanding of what this flow chart

Jar into which the corresponding packet (which is the later need to use jackson)

 

  1.  The first is the client sends a request to http: // localhost: 8080 / springmvc-01 / my.do.
  2. DispatherServlet reach web.xml file to see if meets the requirements of url
  3. DispathcherServlet will query the profile of springmvc find HanderMapping
  4. Find the appropriate controller based on the bean name
  5. Find my Mycontroller class execution method in this class handleRequestInternal
  6. According to modelAndView returned looking springmvc view resolver configuration file.

ViewName and the prefix and suffix made a mosaic. The show splicing of the page to the client

There are three general among HanderMapping

 1. BeanNameUrlHandlerMapping find the corresponding Controller class bean based on the name tag (that is, the kind of default call)

 1  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 2     xsi:schemaLocation="http://www.springframework.org/schema/beans
 3         http://www.springframework.org/schema/beans/spring-beans.xsd">
 4          
 5     <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean>
 6      
 7     <bean name="/my.do" class="com.zhiyou100.hhz.controller.MyController2"></bean>   
 8     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
 9         <property name="prefix" value="/WEB-INF/view/"/>
10         <property name="suffix" value=".jsp"/>
11     </bean>
12  
13 </beans>

 2. SimpleUrlHandlerMapping 根据bean的id查找对应的Controller类。

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xsi:schemaLocation="http://www.springframework.org/schema/beans
 5         http://www.springframework.org/schema/beans/spring-beans.xsd">
 6          
 7     <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
 8         <property name="mappings">
 9             <props>
10                 <prop key="/a.do">my1</prop>
11                 <prop key="/b.do">my2</prop>
12             </props>
13         </property>
14      
15         <bean id="/my1" class="com.zhiyou100.hhz.controller.MyController1"></bean>
16     <bean  id="/my2" class="com.zhiyou100.hhz.controller.MyController2"></bean>
17     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
18         <property name="prefix" value="/WEB-INF/view/"/>
19         <property name="suffix" value=".jsp"/>
20     </bean>
21  
22 </beans>

 

3. ControllerClassNameHandlerMapping 根据controller类的名字找到对应的Controller。

 

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xsi:schemaLocation="http://www.springframework.org/schema/beans
 5         http://www.springframework.org/schema/beans/spring-beans.xsd">
 6          
 7     <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"></bean>
 8     <bean class="com.zhiyou100.hhz.controller.MyController1"></bean>
 9     <bean class="com.zhiyou100.hhz.controller.MyController2"></bean>
10  
11     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
12         <property name="prefix" value="/WEB-INF/view/"/>
13         <property name="suffix" value=".jsp"/>
14     </bean>
15  
16 </beans>

 

Guess you like

Origin www.cnblogs.com/banzhuanlaowang/p/11482117.html