[SpringMVC运行流程]

高并发秒杀系统--SpringMVC整合-LMLPHP

[Handler注解映射技巧]

高并发秒杀系统--SpringMVC整合-LMLPHP

[请求方法的细节处理]

1.如何处理请求参数和方法参数的绑定?

2.如何限制方法接收的请求方式?

3.如何进行请求转发和重定向?

4.如何给数据模型赋值?

高并发秒杀系统--SpringMVC整合-LMLPHP

5.如何返回JSON数据?

高并发秒杀系统--SpringMVC整合-LMLPHP

6.如何获取cookie数据?

高并发秒杀系统--SpringMVC整合-LMLPHP

[SpringMVC的整合配置]

1.在web.xml中配置入口DispatcherServlet

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0"
metadata-complete="true">
<!--用maven创建的web-app需要修改servlet的版本为3.1-->
<!-- SpringMVC配置 -->
<!-- 1:配置DispatcherServlet -->
<servlet>
<servlet-name>seckill-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 配置SpringMVC的Spring配置文件
Mybatis -> Spring -> SpringMVC
-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-*.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>seckill-dispatcher</servlet-name>
<!-- 默认匹配所有的请求 -->
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

2.spring-web.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- SpringMVC配置 -->
<!-- 1:开启SpringMVC注解模式 -->
<!-- 简化配置:
(1)自动注册DefaultAnnotationHandlerMapping,AnnotationMethodHandlerAdapter
(2)提供一些列功能:数据绑定,数字和日期的format @NumberFormat,@DateTimeFormat,
xml,jsonm默认读写支持
-->
<mvc:annotation-driven/> <!-- 2:静态资源默认servlet配置
(1)加入对静态资源的处理:js,gif,png
(2)允许使用"/"做整体映射
-->
<mvc:default-servlet-handler/> <!-- 3:配置jsp 显示ViewResovler -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp"/>
<property name="suffix" value=".jsp"/>
</bean> <!-- 4:扫描web相关的bean -->
<context:component-scan base-package="org.azcode.web"/> </beans>
04-15 08:00