完整代碼以下:html
<?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.xsd">
<!--啓動註解識別,是對包進行掃描,實現註釋驅動Bean定義,同時將bean自動注入容器中使用-->
<context:annotation-config/>
<!--後臺controller程序的路徑-->
<context:component-scan base-package="com.controller"/>
<!--開通靜態資源的訪問,即jsp或html文件-->
<mvc:default-servlet-handler/>
<!--讓全部的Controller可以解析,不可缺乏,<mvc:annotation-driven>裏面那一整段,用來解決@ResponseBody傳輸字符串中文亂碼問題-->
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<!-- 視圖解析器/定位 -->
<bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 配置前綴 -->
<property name="prefix" value="/WEB-INF/jsp/"/>
<!-- 配置後綴 -->
<property name="suffix" value=".jsp"/>
</bean>
<!--文件上傳 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
</beans>
部分截圖以下: