码迷,mamicode.com
首页 > 编程语言 > 详细

springMVC的@ResponseBody中文乱码

时间:2016-05-12 22:48:26      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:

网上很多这种文章但是都没有什么用,有的基本都是只说了一半。
解决方法有很多,一种是局部,也就是单个方法有用的

@RequestMapping(value="", produces = "application/json; charset=utf-8")

鼠标移到produces上有如下提示
技术分享

produces = "text/html; charset=utf-8"
produces = "text/plain; charset=utf-8"

都可以配置


第二种是全局的,配置一次就可以了

<mvc:annotation-driven>
        <mvc:message-converters register-defaults="true">
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <property name="supportedMediaTypes" value = "text/html;charset=UTF-8" />
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

网上也有这种,但是你们是不是<mvc:annotation-driven>不能配置子集
这里只要把你们的spring-mvc-.xsd改成4就可以在<mvc:annotation-driven>下配置了,如下图
技术分享
主要还是spring-mvc-4.0.xsd。改了之后再eclipse中按ALT+/就会出现如下提示
技术分享

这边还要注意一点

<property name="supportedMediaTypes" value = "text/plain;charset=UTF-8" />

text/plain这个还是会中文乱码,用text/html就不会

springMVC的@ResponseBody中文乱码

标签:

原文地址:http://blog.csdn.net/u013239111/article/details/51347949

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!