Spring MVC体系

框架搭建

    web.xml配置

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
 3   <display-name>springMVC</display-name>
 4   <servlet>
 5     <servlet-name>springmvc</servlet-name>
 6     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 7     <init-param>
 8       <param-name>contextConfigLocation</param-name>
 9       <param-value>classpath:springmvc-servlet.xml</param-value>
10     </init-param>
11     <load-on-startup>1</load-on-startup>
12   </servlet>
13   <servlet-mapping>
14     <servlet-name>springmvc</servlet-name>
15     <url-pattern>/</url-pattern>
16   </servlet-mapping>
17 </web-app>

  Spring MVC配置文件

 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     xmlns:mvc="http://www.springframework.org/schema/mvc"
 5     xmlns:p="http://www.springframework.org/schema/p"
 6     xmlns:context="http://www.springframework.org/schema/context"
 7     xsi:schemaLocation="
 8         http://www.springframework.org/schema/beans
 9         http://www.springframework.org/schema/beans/spring-beans.xsd
10         http://www.springframework.org/schema/context
11         http://www.springframework.org/schema/context/spring-context.xsd
12         http://www.springframework.org/schema/mvc
13         http://www.springframework.org/schema/mvc/spring-mvc.xsd">
14         <!-- 配置处理单映射 HandlerMapping -->
15      <!--<bean name="/index.html" class="cn.smbms.controller.IndexController"/>  -->  
16     
17         <!-- 多个映射 注解方式处理 -->
18         <mvc:annotation-driven/>      
19         <context:component-scan base - package="cn.smbms.controller"/> 
20 
21     <!-- 完成视图的对应 -->
22     <!-- 对转向页面的路径解析。prefix:前缀, suffix:后缀 -->
23     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
24         <property name="prefix" value="/WEB-INF/jsp/"/>
25         <property name="suffix" value=".jsp"/>
26     </bean>
27 
28 </beans>

Spring MVC体系结构

Spring MVC框架特点

 View to Controller

 Controller to View

猜你喜欢

转载自www.cnblogs.com/1097123611-abc/p/10435173.html