springmvc-servlet.xml
引入命名空间,引入注解
命名空间:
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-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
<context:annotation-config/>
注册并只将controller bean引入到springmvc容器中
<context:component-scan base-package="com.wtw">
<context:include-filter type="annotaion" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- 处理静态资源的请求-->
<mvc:default-servlet-handler />
<!--
<mvc:annotation-driven /> 是一种简写形式,完全可以手动配置替代这种简写形式,简写形式可以让初学都快速应用默认配置方案。
<mvc:annotation-driven /> 会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,是spring MVC为@Controllers分发请求所必须的。
并提供了:数据绑定支持,@NumberFormatannotation支持,@DateTimeFormat支持,@Valid支持,读写XML的支持(JAXB),读写JSON的支持(Jackson)。-->
<mvc:annotation-driven/>
<!--静态资源的绑定-->
<mvc:resources location="/script/js/*" mapping="/js/**" />
<mvc:resources location="/style/images/*" mapping="/img/**" />
<mvc:resources location="/style/css/*" mapping="/css/**" />
<mvc:resources location="" mapping=""/>
<!-- 配置拦截器及拦截目标 -->
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/stu/*" />
<mvc:exclude-mapping path="/login" />
<bean class="com.wtw.interceptor.LoginInterceptor">
</bean>
</mvc:interceptor>
</mvc:interceptors>
<!-- 逻辑视图的视图解析器,将得到的逻辑视图添加前缀后缀获取最终的视图页面 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
id="internalResourceViewResolver">
<!-- 前缀 -->
<property name="prefix" value="/WEB-INF/jsp/" />
<!-- 后缀 -->
<property name="suffix" value=".jsp" />
</bean>
<!-- 文件上传 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="2048000"></property>
<property name="defaultEncoding" value="UTF-8"></property>
</bean>