springMVC.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: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
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- 开启 controller层组件扫描 -->
<context:component-scan base-package="com.star.controller"/>
<!-- 默认 servlet 处理器,过滤静态资源,如 .js、.css 文件-->
<mvc:default-servlet-handler/>
<!--
开启 mvc 注解支持
自动注册 DefaultAnnotationHandlerMapping 与 AnnotationMethodHandlerAdapter
自动初始化七个数据转换器,详情看:https://blog.csdn.net/chidan4048/article/details/100641046
-->
<mvc:annotation-driven/>
<!-- 配置内部资源视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<!-- 配置登录拦截器 -->
<mvc:interceptors>
<mvc:interceptor>
<!-- 代表 /book 下的所有请求 -->
<mvc:mapping path="/book/**"/>
<!-- 自定拦截器路径 -->
<bean class="com.star.utils.LoginInterceptor"/>
</mvc:interceptor>
</mvc:interceptors>
<!-- 配置文件解析器 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 自定默认编码,默认为 IOS -->
<property name="defaultEncoding" value="utf-8"/>
<!-- 最大上传尺寸 10M -->
<property name="maxUploadSize" value="10000000"/>
<!-- 最大内存尺寸 5M -->
<property name="maxInMemorySize" value="5000000"/>
</bean>
</beans>