Spring MVC五大核心组件及实现Spring MVC 的步骤

1.Spring Web  MVC 五大核心组件 
  DispatcherServlet    控制器入口 负责分发请求 
  HandlerMapping       负责根据请求 找到对应的控制器
  Controller           真正处理请求的控制器 
  ModelAndView         封装数据信息和视图信息的 
  ViewResolver         视图处理器 通过处理找到对应的页面


2.实现Spring MVC 的步骤 
  2.1 建立一个 动态web 项目  在WEB-INF 下 建立一个 hello.jsp  
     导入jar包(mvc  ioc)   拷贝Spring 配置文件到 src 下 
  2.2 在web.xml 中 配置  DispatcherServlet  
    关联Spring 的配置文件 
  2.3 在Spring 的配置文件中 配置HandlerMapping 接口对应的实现类 
  SimpleUrlHandlerMapping   指定请求路径和 对应的处理控制器的
    对应关系
  2.4 写一个 控制器类  实现 Controller 接口   完成返回 ModelAndView
     赋值hello.jsp 对应的视图信息
  2.5 在Spring 容器中创建 控制器对象  并关联请求和控制器的对象关系   
  2.6 在Spring 配置文件 配置 视图处理器接口 ViewResolver 对应的

     实现类 InternalResourceViewResolver。


##配置文件配置

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:jdbc="http://www.springframework.org/schema/jdbc"  
xmlns:jee="http://www.springframework.org/schema/jee" 
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop" 
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd">
   <!--  配置HandlerMapping  -->
   <bean  id="handlerMapping"   
      class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
      <!--  建立请求 和 控制器的对应关系  key 请求路径  hello 是控制器id --> 
      <property name="mappings">
           <props>
                <prop key="/hello.do" >hello</prop>
           </props>
      </property>
   </bean>
   <!--  配置控制器对象  -->
   <bean  id="hello" class="com.xdl.controller.HelloController"></bean>
   <!--  配置视图处理器  -->
   <bean  id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
      <property name="suffix"  value=".jsp"></property> 
   </bean>
</beans>

  • 3
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值