【springMVC】Controller返回中文亂碼

在spring-mvc.xml下增加以下代碼:

<mvc:annotation-driven
			content-negotiation-manager="contentNegotiationManager">
		<mvc:message-converters register-defaults="true">
			<!-- 將StringHttpMessageConverter的默認編碼設爲UTF-8 -->
			<bean class="org.springframework.http.converter.StringHttpMessageConverter">
				<constructor-arg value="UTF-8" />
			</bean>
		</mvc:message-converters>
	</mvc:annotation-driven>
	<!-- REST中根據URL後綴自動判定Content-Type及相應的View -->
	<bean id="contentNegotiationManager"
		  class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
		<property name="mediaTypes">
			<map>
				<entry key="xml" value="application/xml" />
				<entry key="json" value="application/json" />
			</map>
		</property>
		<property name="ignoreAcceptHeader" value="true" />
		<property name="favorPathExtension" value="true" />
	</bean>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章