SpringMVC之处理响应中文内容乱码

SpringMVC的@ResponseBody返回中文乱码的原因是Controller层编程时使用的编码格式是UTF-8,@ResponseBody返回到jsp页面时SpringMVC默认告诉浏览器解码的编码格式为ISO-8859-1。
我们可以在配置文件中的mvc:annotation-driven中配置一个专门处理返回内容是文本信息的MessageConverter。此方法是全局的、针对整个项目的

<mvc:annotation-driven>
	<mvc:message-converters>
		<!-- 处理响应中文内容乱码 -->
		<bean class="org.springframework.http.converter.StringHttpMessageConverter">
			<property name="defaultCharset" value="UTF-8" />
			<property name="supportedMediaTypes">
				<list>
					<value>text/html</value>
					<value>application/json</value>
				</list>
			</property>
		</bean>
	</mvc:message-converters>
</mvc:annotation-driven>

版权声明:本文为ZXY_9264_ANG原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。