在进行spring框架搭建的时候,需要进行spring-mvc.xml文件的配置:

spring-mvc示例:

<?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">

    <!-- 配置注解驱动:可以自动加载处理器映射器和处理器适配器,因此可以代替上述单独配置处理器映射器和处理器适配器  -->
    <mvc:annotation-driven />

    <context:component-scan base-package="com.ash.cn.controller"/>

    <!-- 配置视图解析器 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!-- 配置逻辑视图的前缀-->
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <!-- 配置逻辑视图的后缀 -->
        <property name="suffix" value=".jsp"/>
    </bean>

    <!-- 配置文件上传解析器:id必须为multipartResolver-->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- 设置文件上传大小 -->
        <property name="maxUploadSize" value="500000"/>
    </bean>

    <!--静态资源释放-->
   <!-- <mvc:default-servlet-handler/>-->
    <mvc:resources location="WEB-INF/static/" mapping="/static/**"/>

</beans>

spring-mvc.xml配置文件中一般配置有如下几项:

① 注解驱动

②扫描controller包

③视图解析

④静态资源释放

⑤文件上传处理器

...