---
title: "SpringMVC注解@ResponseBody返回数据中文乱码问题"
author: "静默时间-花开灿然"
date: "2015-07-26T11:13:30Z"
tags: []
categories: ["研发管理"]
slug: "springmvc-responsebody"
draft: false
lastmod: "2015-07-26T11:13:30Z"
id: 2230292
url: "https://zhen217.iteye.com/blog/2230292"
---

中文乱码是因为springmvc使用的默认处理字符集是iso-8859-1。

方法1：给需要返回字符串的方法添加注解：

```
@RequestMapping(value = "/getXXX",produces = "text/html;charset=UTF-8")
@ResponseBody
```

 方法2：在配置文件中设置：

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