zoukankan      html  css  js  c++  java
  • spring MVC (学习笔记)

    web.xml 相关配置

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="
            http://xmlns.jcp.org/xml/ns/javaee
            http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    version="3.1" metadata-complete="true">
      <display-name>Archetype Created Web Application</display-name>

        <!-- Spring应用上下文,层次化的ApplicationContext -->

      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring-*.xml</param-value>
      </context-param>

      <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>

      <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!-- DispatcherServlet对应的上下文配置,默认为/WEB-INF/$servlet-name$-servlet.xml -->
        <init-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>classpath:spring/web-spring-mvc.xml</param-value>
        </init-param>
      </servlet>
      <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <!-- dispatcher拦截所有请求 -->
        <url-pattern>/</url-pattern>
      </servlet-mapping>
    </web-app>

    对应的springmvc 的相关配置

    <?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
    ">
      <!-- 配置spring -->
      <!-- 1:开启SpringMVC注解模式 -->
      <!-- 简化配置:
        (1)自动注册DefaultAnnotationHandlerMapping,AnnotationMethodHandlerAdapter
        (2)提供一系列:数据绑定,数字和日期的format @NumberFormat,@DataTimeFormat,xml,json默认读写支持
      -->
      <mvc:annotation-driven/>
      <!-- 2:servlet-mapping 映射路径:"/" -->
      <!-- 静态资源默认servlet配置
        1.加入对静态资源的处理
        2.欲需使用"/"做整体映射
      -->
      <mvc:default-servlet-handler/>
      <!-- 3:配置jsp 显示ViewResolver -->
      <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="com.cgj.spring.mvc.controller">
        <!-- 只扫描@Controller标注的类,不扫描其他标注的类 -->
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
      </context:component-scan>
    </beans>

  • 相关阅读:
    VC++中使用ADO方式操作ACCESS数据库
    运维工程师必会的109个Linux命令
    linux上安装配置samba服务器
    ubuntu如何实现访问实际网络中windows共享文件夹
    R语言 入门知识--常用操作和例子
    坚持你选择的路
    scala eclipse plugin 插件安装
    Linux安装卸载Mysql数据库
    Hadoop HA高可用性架构和演进分析(转)
    Spring 系列: Spring 框架简介 -7个部分
  • 原文地址:https://www.cnblogs.com/LionheartCGJ/p/6759772.html
Copyright © 2011-2022 走看看