SpringMVC给前段返回的JSON数据中文乱码问题

由于SpringMVC的认编码问题(不支持中文),所以在@ResponseBody里返回中文时会出现乱码。
方法一,在XML文档里写入全局设置,改为UTF8


   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

<context:component-scan base-package="base.code.controller"/>

//UTF-8编码指定。

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
id="internalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".html"/>

方法二,在@RequestMapping中添加produces = "text/html;charset=utf-8",但是次方法只适用于局部。

相关文章

SpringMVC1.MVC架构MVC是模型(Model)、视图(View)、控制...
SpringMVC学习笔记1.SpringMVC应用1.1SpringMVC简介​Spring...
11.1数据回显基本用法数据回显就是当用户数据提交失败时,自...
一、SpringMVC简介1、SpringMVC中重要组件DispatcherServlet...
1.它们主要负责的模块Spring主要应用于业务逻辑层。SpringMV...
3.注解开发Springmvc1.使用注解开发要注意开启注解支持,2.注...