您的位置:首页 > 编程语言 > Java开发

spring mvc 4+ @ResponseBody 中文乱码

2016-05-17 11:47 741 查看
(1)加上produces = {"application/json;charset=UTF-8"}

@RequestMapping(value="/birthday.chtm",produces = {"application/json;charset=UTF-8"})

(2)在spring-mvc.xml中配置

注意 4+版本的spring-mvc要使用 http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg value="#{T(java.nio.charset.Charset).forName('UTF-8')}"/>
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
<value>text/html;charset=UTF-8</value>
<value>applicaiton/javascript;charset=UTF-8</value>
</list>
</property>
<property name="writeAcceptCharset"><value>false</value></property>
</bean>
<bean
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json; charset=UTF-8</value>
<value>application/x-www-form-urlencoded; charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: