1.Spring Mvc 是控制层的Spring框架,替换Servlet,除了它以外,还有 struct1和 struct2
区别:
1.struct1被struct2 取代
2.struct2:采用 prototype多例模式,内存消耗快,经常会出现内存溢出,优点是成员变量线程安全
3.Spring Mvc:采用singleton单例模式,使用它节省内存空间,但是成员变量需要考虑线程安全问题----线程安全的解决,可以参考http://t.csdn.cn/JKNLp
2.Spring MVC 原理 
1.客户端发送请求给DispatcherServlect前端控制器
2.DispatcherServlect前端控制器向handlerMapping处理器映射器发送请求
3.HandlerMapping处理器映射器向DispatcherServlect前端控制器发送处理器执行链和拦截器链
4.DispatcherServlect前端控制器向处理器映射器对应的HandlerAdapter处理器适配器发送请求
5.HandlerAdapter处理器适配器查找Handler处理器
6.Handler处理器执行handler
7.handler向HandlerAdapter处理器适配器返回ModleAndView
8.HandlerAdapter处理器适配器向DispatcherServlect前端控制器返回MadleAndView
9.DispatcherServlect前端控制器向ViewResolver视图解析器发送请求,帮助解析视图
10.ViewResolver视图解析器向DispatcherServlect前端控制器返回View
11.DispatcherServlect前端控制器会拿数据进行渲染,生成HTML静态代码
12.将静态代码发送到客户端进行响应
1.创建web工程
2.导入依赖:

5个核心依赖+日志依赖+web.jar+webmvc.jar+aop.jar
3.创建applicationContext.xml
- "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:p="http://www.springframework.org/schema/p"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:mvc="http://www.springframework.org/schema/mvc"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- https://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/aop
- https://www.springframework.org/schema/aop/spring-aop.xsd
- http://www.springframework.org/schema/mvc
- https://www.springframework.org/schema/mvc/spring-mvc.xsd">
-
-
- <context:component-scan base-package="com.sofwin">context:component-scan>
4.web.xml
- <servlet>
- <servlet-name>aservlet-name>
- <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
- <init-param>
- <param-name>contextConfigLocationparam-name>
- <param-value>classpath:applicationContext.xmlparam-value>
- init-param>
- servlet>
-
- <servlet-mapping>
- <servlet-name>aservlet-name>
-
- <url-pattern>/url-pattern>
- servlet-mapping>
5.创建同步请求:需要一个普通的class文件
- // ioc的衍生注解 webmvc,控制层的类
- @Controller
- public class testController {
- @RequestMapping("/a")
- public String test01() {
- return "/test01.jsp";
- }
- }
@RequestMapping
GetMapping:只能接收get类型的请求
PostMapping:只能接收Post类型的请求
DeleteMapping:只能接收Delete类型的请求