第一种、注解

    @RequestMapping(value = "/test.do", method = {RequestMethod.GET},produces = "text/plain;charset=utf-8")
@ResponseBody
public String test(HttpServletResponse response) {
  }

第二种、spring mvc 配置文件

    <!-- 会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter
两个bean -->
<mvc:annotation-driven>
<!-- Springmvc处理@responsebody 使用的是默认编码iso-8859-1 所以改变编码 -->
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg name="defaultCharset" value="UTF-8"></constructor-arg>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>

Java-SpringMvc-@ResponseBody返回中文字符串乱码的更多相关文章

  1. Spring MVC @ResponseBody返回中文字符串乱码问题

    朋友做小项目练手的时候遇到的,着实让他郁闷够呛..这个问题的确很恶心.. 项目中引用的json包,直接用@ResponseBody注解返回json字符串..有关这个的乱码问题网上很多,各种花样各种转码 ...

  2. 解决Spring MVC @ResponseBody返回中文字符串乱码问题

    spring mvc使用的默认处理字符串编码为ISO-8859-1 解决方法: 第一种方法: 对于需要返回字符串的方法添加注解,如下: @RequestMapping(value="/use ...

  3. SpringMVC使用@ResponseBody注解返回中文字符串乱码的问题

    先说一下我的经历,以及解决问题的而过程. 在使用SpringMVC的时候,最开始的时候在配置文件中使用<mvc:annotation-driven />去自动注册DefaultAnnota ...

  4. spring mvc 返回乱码SpringMVC使用@ResponseBody注解返回中文字符串乱码的问题

    原文地址:https://www.cnblogs.com/fzj16888/p/5923232.html 先说一下我的经历,以及解决问题的而过程. 在使用SpringMVC的时候,最开始的时候在配置文 ...

  5. SpringMVC @ResponseBody返回中文乱码

    SpringMVC的@ResponseBody返回中文乱码的原因是SpringMVC默认处理的字符集是ISO-8859-1, 在Spring的org.springframework.http.conv ...

  6. SpringMVC 直接返回中文字符串时,出现乱码(?)的问题

    在springmvc.xml中加入下面配置得以解决. <mvc:annotation-driven> <mvc:message-converters> <bean cla ...

  7. SpringMVC ResponseBody返回中文乱码解决方案

    @RequestMapping(value = "/getForm") @ResponseBody public List<String> getForm(String ...

  8. 解决SpringMVC的@ResponseBody返回中文乱码

    SpringMVC的@ResponseBody返回中文乱码的原因是SpringMVC默认处理的字符集是ISO-8859-1,在Spring的org.springframework.http.conve ...

  9. Springboot @ResponseBody返回中文乱码

    最近我在把Spring 项目改造Springboot,遇到一个问题@ResponseBody返回中文乱码,因为response返回的content-type一直是application/json;ch ...

随机推荐

  1. springaop---->springaop的使用(一)

    与大多数技术一样, AOP 已经形成了自己的术语.描述切面的常用术语有通知(advice).切点(pointcut)和连接点(join point).从今天开始,我们对spring的切面编程做一个总结 ...

  2. css笔记 - 张鑫旭css课程笔记之 line-height 篇

    一.line-height line-height: 指两行文字基线之间的距离. 行高200px表示两行文字基线之间的距离是200px: 二.基线:baseline 字母x下边缘的位置 基线是任意线定 ...

  3. H5 password自动记录取消

    最近完成一个项目时需要取消谷歌浏览器的密码自动填充功能,为了用户方便,大多浏览器都有保存某个网站的密码并在后面再打开这个网站且需要输入密码的时候自动填充.这个功能是方便,但是我们有时候不需要使用这个功 ...

  4. [原]linux下将网卡设置为混杂模式

    设置为混杂模式ifconfig eth2 promisc取消设置ifconfig eth2 -promisc ------------------------------------------ 下面 ...

  5. [转]redhat7(centos7) not registered to Red Hat Subscription Management

    [root@controller0 ~]# yum install ntp Loaded plugins: fastestmirror, product-id, search-disabled-rep ...

  6. CSS属性绘制图形(一)

    div部分: <div class="react-logo"> <div class="reactive"></div> & ...

  7. 【读书笔记】setsockopt

    setsockopt   设置套接口的选项. #include <sys/types.h> #include <sys/socket.h> int setsockopt(int ...

  8. 【CF888E】Maximum Subsequence 折半搜索

    [CF888E]Maximum Subsequence 题意:给你一个序列{ai},让你从中选出一个子序列,使得序列和%m最大. n<=35,m<=10^9 题解:不小心瞟了一眼tag就一 ...

  9. 兵器簿之Alcatraz(插件管理神器)的配置和使用

    Alcatraz是一款开源框架,帮助我们管理和安装Xcode需要的一些插件,很赞,安装也很简单: 终端输入: curl -fsSL https://raw.githubusercontent.com/ ...

  10. yii---load怎么使用

    在用YII进行二次开发的时候,看到登录方法有一个load的方法: public function actionLogin() { if (Yii::$app->request->isPos ...