SpringMVC 中文乱码解决方案
来源:互联网 发布:奥利奥爆浆油条淘宝 编辑:程序博客网 时间:2024/06/14 03:33
SpringMVC 中文乱码解决方案
首先了解源码
/** * Implementation of {@link HttpMessageConverter} that can read and write strings. * * <p>By default, this converter supports all media types ({@code */*}), * and writes with a {@code Content-Type} of {@code text/plain}. This can be overridden * by setting the {@link #setSupportedMediaTypes supportedMediaTypes} property. * * @author Arjen Poutsma * @since 3.0 */public class StringHttpMessageConverter extends AbstractHttpMessageConverter<String> {public static final Charset DEFAULT_CHARSET = Charset.forName("ISO-8859-1");private final Charset defaultCharset;private final List<Charset> availableCharsets;private boolean writeAcceptCharset = true;
关键点:
源码默认的编码是ISO-8859-1:public static final Charset DEFAULT_CHARSET = Charset.forName(“ISO-8859-1”);
修改方式:by setting the {@link #setSupportedMediaTypes supportedMediaTypes} property
解决方案
1、在spring-servlet.xml中添加
<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>
2、在代码里写
@RequestMapping(value="/test",produces = "application/json; charset=utf-8")@ResponseBodypublic String testUTF8(HttpServletRequest request,HttpServletResponse response){..........}
阅读全文
0 0
- springMVC中文乱码解决方案
- SpringMVC 中文乱码解决方案
- SpringMvc POST中文乱码解决方案
- SpringMVC POST中文乱码解决方案
- SpringMVC框架中文乱码解决方案
- springmvc中POST中文乱码解决方案
- SpringMVC POST/GET 中文乱码 解决方案
- SpringMVC之GET中文乱码解决方案
- springmvc responseBody返回中文乱码解决方案
- springmvc 上传图片中文乱码解决方案
- SpringMVC重定向中文乱码解决方案
- SpringMVC传值中文乱码解决方案
- SpringMVC之POST中文乱码解决方案。
- SpringMVC传值中文乱码解决方案
- Springmvc中@RequestParam传值中文乱码解决方案:
- Springmvc中@RequestParam传值中文乱码解决方案
- SpringMVC form表单中文乱码解决方案(基于JavaConfig)
- Springmvc中@RequestParam传值中文乱码解决方案
- Java IO最详解
- 通用OA系统如何防止后门检测的解决方案,以通达OA为例说明
- 手把手教你给一个iOS app配置多个环境变量
- Xstream使用
- 浅析 React 工作原理
- SpringMVC 中文乱码解决方案
- Windows下的MySQL安装、MySQL-Front安装
- 数组中的逆序对
- python中matplotlib的颜色及线条控制
- [Leetcode] 385. Mini Parser 解题报告
- JAVA 并发编程随笔【六】线程的竞态条件与临界区
- 带修改的莫队算法【JZOJ 4594】【UVa 12345】Dynamic len
- #快速幂#POJ 2991 2011&&luogu 1226 取余运算
- LInux安装ARPACK库