admin管理员组

文章数量:1794759

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

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="www.springframework/schema/beans"  xmlns:xsi="www.w3/2001/XMLSchema-instance" xmlns:context="www.springframework/schema/context"  xmlns:jdbc="www.springframework/schema/jdbc"   xmlns:jee="www.springframework/schema/jee"  xmlns:tx="www.springframework/schema/tx" xmlns:aop="www.springframework/schema/aop"  xmlns:mvc="www.springframework/schema/mvc" xmlns:util="www.springframework/schema/util" xmlns:jpa="www.springframework/schema/data/jpa" xsi:schemaLocation=" www.springframework/schema/beans www.springframework/schema/beans/spring-beans-4.1.xsd www.springframework/schema/context www.springframework/schema/context/spring-context-4.1.xsd www.springframework/schema/jdbc www.springframework/schema/jdbc/spring-jdbc-4.1.xsd www.springframework/schema/jee www.springframework/schema/jee/spring-jee-4.1.xsd www.springframework/schema/tx www.springframework/schema/tx/spring-tx-4.1.xsd www.springframework/schema/data/jpa www.springframework/schema/data/jpa/spring-jpa-1.3.xsd www.springframework/schema/aop www.springframework/schema/aop/spring-aop-4.1.xsd www.springframework/schema/mvc www.springframework/schema/mvc/spring-mvc-4.1.xsd www.springframework/schema/util www.springframework/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>

本文标签: 五大组件步骤核心spring