1、SpringMVC是什么?
springMVC是spring framework 的后续产品,是一个mvc的框架。
前端控制器:Dispathcher ,用户接收请求
处理器映射器 DefaultAnnotationHandlerMapping 把一个url映射到具体的Controller上,
处理器设配器 AnnotationHandlerAdapter 把一个url映射到对应Control类的方法上
视图解析器 InternalResourceViewResolver 把一个ModelAndView的逻辑视图名称解析为具体的View
2、SpringMVC的实现--HelloWorld
3、URL映射
1、配置一个action多个URL
2、URL请求参数映射
3、URL通配符
4、url必须包含某个参数,或不能有某个参数,等于和不等于。
4、数据绑定
1.@RequestParam,绑定单个请求数据,可以是URL中的数据,表单提交的数据或上传的文件;
2.@PathVariable,绑定URL模板变量值;
3.@CookieValue,绑定Cookie数据;
4.@RequestHeader,绑定请求头数据;
5.@ModelAttribute,绑定数据到Model;
6.@SessionAttributes,绑定数据到Session;
7.@RequestBody,用来处理Content-Type不是application/x-www-form-urlencoded编码的内容,例如application/json, application/xml等;
8.@RequestPart,绑定“multipart/data”数据,并可以根据数据类型进项对象转换;
5、自定义参数绑定
数据类型转换
6、springmvc转发重定向
默认是forward 转发。
return “foward:index.action”,
return "redirect::index.action";
7、数据回显
ModelAndView :相当于Request
Request
Session
ServletContext
8、拦截器
1、实现拦截器类 HandlerInterceptorAdapter
2、配置使用拦截器类
<mvc:interceptors>
<!-- 使用bean定义一个Interceptor,直接定义在mvc:interceptors根下面的Interceptor将拦截所有的请求-->
<!-- <bean class="com.zhouyuan.action.MyInterceptor" /> -->
<mvc:interceptor>
<mvc:mapping path="/interceptor/**" /> <!-- 定义在mvc:interceptor下面的表示是对特定的请求才进行拦截的 -->
<bean class="com.zhouyuan.test.MyInterceptor" />
</mvc:interceptor>
</mvc:interceptors>
9、异常处理
10、文件上传下载
11、使用JSON
12、SpringMVC实现Restful
13、国际化
14、springmvc事务处理