首页 > 编程语言 > 详细

解决SpringMVC中文乱码问题 -----这是服务器返回参数到前端中文乱码

时间:2019-04-14 23:00:11      阅读:163      评论:0      收藏:0      [点我收藏+]

方法一,使用(produces = "application/json; charset=utf-8"):

    @RequestMapping(value="/getUsersByPage",produces = "application/json; charset=utf-8")
//    @RequestMapping("/getUsersByPage")
    @ResponseBody
    public String getUsersByPage(String page,String rows,String text,HttpServletRequest request,HttpServletResponse response){

方法二,在spring-mvc.xml中添加:

<!--让所有的Controller能够解析,不可缺少,<mvc:annotation-driven>里面那一整段,用来解决@ResponseBody传输字符串中文乱码问题-->
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>

技术分享图片

 

 

 

解决SpringMVC中文乱码问题 -----这是服务器返回参数到前端中文乱码

原文:https://www.cnblogs.com/c2g5201314/p/10707988.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!