Spring框架-原理图和基本配置 

一,springMVC流程图 

 

  组件分析:
	1;前端控制器(只需配置) 作用:只负责分发请求。可以很好的对其他组件进行解耦合。
	2;处理器映射器(只需配置)
	3;处理器适配器(只需配置)
	4;处理器(需要开发)
	5;视图解析器(只需配置)
	6;视图(需要开发)
二,SpringMVC快速入门

  1.创建maven工程
  2.导入springmvc依赖及servlet-api
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>4.3.12.RELEASE</version>
  </dependency>
  <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
  </dependency>
3.在web.xml配置前端控制器
  <servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
4.创建Controller
  @org.springframework.stereotype.
  Controller("/test")
    public class TestController implements Controller {
            @Override public ModelAndView handleRequest(HttpServletRequest request,
                  HttpServletResponse response) throws Exception {
      System.out.println("Hello,SpringMVC!");
      return null; }
      }
5.创建springmvc配置文件
在WEB-INF下创建springmvc-servlet.xml
<?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:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context.xsd
      http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.lanou.controller"/>
</beans>








posted on 2018-06-08 19:32  北冥丶中郎将  阅读(169)  评论(0编辑  收藏  举报