<?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-3.2.xsd">
<!-- HandlerMapping 无需配置,SpringMVC可以默认启动,DefaultAnnotationHandlerMapping annotation-driven HandlerMapping -->
<!-- 配置SpringMVC -->
<!-- 1.开启SpringMVC注解模式 -->
<!-- 简化配置: (1)自动注册DefaultAnootationHandlerMapping,AnotationMethodHandlerAdapter
(2)提供一些列:数据绑定,数字和日期的format @NumberFormat, @DateTimeFormat, xml,json默认读写支持 -->
<mvc:annotation-driven/>
<!-- 2.静态资源默认servlet配置
(1)加入对静态资源的处理:js,gif,png
(2)允许使用"/"做整体映射 , 不会拦截,当为静态资源。
这两个都是处理静态资源的,区别可以理解成一个是指定一个自定义的serlvet来专门处理相应的静态资源,如果不指定
会默认找default名字的servlet
而<mvc:resources>的好处可以理解成是静态资源可以在我们项目中的任意位置配置,只需要将对应的位置声明即可
-->
<mvc:resources mapping="/resources/**" location="/resources/"/>
<mvc:default-servlet-handler/>
<!-- 3.定义视图解析器 -->
<!-- ViewResolver:视图解析器。可以配置多个 但是一定要将这个ViewResolver(InternalResourceViewResolver)
放到最后 -->
<!-- 解析json格式的传参和封装数据到页面,注意spring的版本和对应的配置方式 -->
<!-- spring-4.2以后 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/html/"></property>
<property name="suffix" value=".html"></property>
</bean>
<!-- 4.扫描web相关的bean -->
<!-- 激活组件扫描功能,扫描aop的相关组件组件 -->
<context:component-scan base-package="com.imooc.web"/>
</beans>