简单配置springmvc-servlet.xml

<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">

  <!-- 1、配置基于注解的映射器和适配器 -->
  <mvc:annotation-driven/>

  <!-- 处理静态资源 -->
  <mvc:default-servlet-handler/>
  <!-- <mvc:resources location="/css/" mapping="/css/**"></mvc:resources>
  <mvc:resources location="/vue/" mapping="/vue/**"></mvc:resources>
  <mvc:resources location="/js/" mapping="/js/**"></mvc:resources> -->

  <!-- 2、视图解析器 -->
  <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/"></property>
    <!-- <property name="suffix" value=".jsp"></property> -->
  </bean>

  <!-- 3、配置基于上下文进行组件扫描 -->
  <context:component-scan base-package="com.ssm.controller"></context:component-scan>

  <!-- 4、SpringMVC文件上传规定需配置 MultipartResolver处理器 -->
  <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <property name="defaultEncoding" value="UTF-8" />
    <!-- 指定所上传文件的总大小,单位字节。注意maxUploadSize属性的限制不是针对单个文件,而是所有文件的容量之和 -->
    <property name="maxUploadSize" value="10485760" />
  </bean>

</beans>

原文地址:https://www.cnblogs.com/4AMLJW/p/ssm_ljw_201909091536.html