zoukankan      html  css  js  c++  java
  • 高并发秒杀系统--SpringMVC整合

    [SpringMVC运行流程]

    [Handler注解映射技巧]

    [请求方法的细节处理]

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

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

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

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

    5.如何返回JSON数据?

    6.如何获取cookie数据?

    [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>
  • 相关阅读:
    文档01_基础
    文档07_JavaScript_ajax
    文档02_JavaScript
    文档06_JavaScript_面相对象
    文档05_JavaScript_节点
    文档06_Asp.net2.0_01
    文档04_JavaScript_事件
    文档05_多线程
    文档03_JavaScript_函数
    根据日期计算星座
  • 原文地址:https://www.cnblogs.com/azcode/p/6718612.html
Copyright © 2011-2022 走看看