<mvc:annotation-driven>會自動註冊RequestMappingHandlerMapping與RequestMappingHandlerAdapter兩個Bean,這是Spring MVC爲@Controller分發請求所必需的,而且提供了數據綁定支持,@NumberFormatannotation支持,@DateTimeFormat支持,@Valid支持讀寫XML的支持(JAXB)和讀寫JSON的支持(默認Jackson)等功能。web
使用該註解後的springmvc-config.xml:spring
<!-- spring 能夠自動去掃描 base-package下面的包或子包下面的Java文件,若是掃描到有Spring的相關mvc
註解的類,則把這些類註冊爲Spring的bean -->app
<context:component-scan base-package="org.fkit.controller"/>jsp
<!--設置配置方案 -->spa
<mvc:annotation-driven/>component
<!--使用默認的Servlet來響應靜態文件-->orm
<mvc:default-servlet-handler/>xml
<!-- 視圖解析器 -->servlet
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!-- 前綴 --> <property name="prefix"> <value>/WEB-INF/content/</value> </property> <!-- 後綴 --> <property name="suffix"> <value>.jsp</value> </property> </bean>