SpringBoot乱码
第一步:
第一步,约定好传参编码格式
不管是运用httpclient,还是原生http,都要设置传参的编码,为了统一,这儿全部设置为utf-8
第二步,修正application.properties文件
添加如下配置信息:
spring.http.encoding.force=true
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
server.tomcat.uri-encoding=UTF-8
此刻拦截器中回来的中文现已不乱码了,可是controller中回来的数据仍旧乱码。
第三步,重写configureMessageConverters方法
package com.springboot.bootdemo01; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import java.nio.charset.Charset;
import java.util.List; /**
* @author liufh
* @date 2018/9/2611:24
*/
@Configuration
public class MyWebAppConfigurer extends WebMvcConfigurerAdapter
{
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters)
{
super.configureMessageConverters(converters);
converters.add(responseBodyConverter());
} @Bean
public HttpMessageConverter responseBodyConverter()
{
StringHttpMessageConverter converter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
return converter;
}
}
SpringBoot乱码的更多相关文章
- 解决springboot乱码和window cmd乱码
@Bean public FilterRegistrationBean filterRegistrationBean() { FilterRegistrationBean registration = ...
- 解决springboot序列化 json数据到前端中文乱码问题
前言 关于springboot乱码的问题,之前有文章已经介绍过了,这一篇算是作为补充,重点解决对象在序列化过程中出现的中文乱码的问题,以及后台报500的错误. 问题描述 spring Boot 中文返 ...
- java web 学习十(HttpServletRequest对象1)
一.HttpServletRequest介绍 HttpServletRequest对象代表客户端的请求,当客户端通过HTTP协议访问服务器时,HTTP请求头中的所有信息都封装在这个对象中,通过这个对象 ...
- springboot使用i18n时properties文件中文乱码
在springboot使用i18n进行国际化文件配置时,文件名为messages_zh_CN.properties的文件中填写中文信息,当使用浏览器进行访问时,出现中文乱码,此时在idea中进行修改s ...
- Springboot 之 解决IDEA读取properties配置文件的中文乱码问题
问题描述 当在.properties的配置文件中有中文时,读取出来的总是乱码.比如我的application.properties配置文件的内容如下: server.port=9090 test.ms ...
- SpringBoot更改HttpMessageConverters使用FastJson出现乱码问题
1.出现问题的现象!如下截图,使用SpringBoot 进行开发,接口返回的内容出现中文乱码? 接口内容想要返回的内容: 页面返回内容: 惊喜不?意外不? 为什么出现这个情况?不例外的话,很多同事都是 ...
- springboot使用fastjson中文乱码解决方法 【转载】
以前使用fastjson替换jackson时,没有直接在页面打印过json,都是js使用没有出现乱码,偶然 打印出来出现了中文乱码 之前使用的配置方式 @Configuration public cl ...
- 【转】Spring-boot 字符集设置 解决乱码方案
使用spring-boot开发时候,有时候程序没事,往往不经意会造成中文到前端变成乱码(????这样情况) 下面给出spring-boot项目统一字符集设置方案: 1.Spring Boot修改编码方 ...
- Springboot使用FastJson后,接口返回中文乱码的问题解决。
哎,天下文章一大抄,到处都是一模一样的教你怎么替换掉jackson成fastjson的,可后续中文乱码网上居然没一篇文章.翻了一会源码还是写个文章共享下吧.免得后来人又浪费时间折腾. 在springb ...
随机推荐
- 2018-03-11 20165235 祁瑛 Java第二周考试总结
20165235 祁瑛 Java第二周考试总结 课后习题p16 代码编写 class Person { void speakHello (){ System.out.print("nin h ...
- int和intege相比
int i = 100; Integer i1 = 100; Integer i2 = new Integer(100); system.out.println(i == i1);true syste ...
- maven聚合工程无法install
对于maven聚合工程,有时候执行maven命令进行mvn clean install时会出一些莫名奇妙的错误: 一直报告找不到符号,仔细看了项目源代码也不知道是什么原因.首先确保项目所在路径为英文路 ...
- hexo添加404公益界面
http://hellolb.top/2018/08/16/hexo添加404公益界面/ hexo个人博客添加404公益界面,这里我使用的腾讯404公益界面 我的博客主题是hexo+yilia,其实所 ...
- 003.MongoDB主要概念
一 对比关系 SQL术语/概念 MongoDB术语/概念 解释/说明 database database 数据库 table collection 数据库表/集合 row document 数据记录行 ...
- 使用zabbix监控oracle表空间
0.概述 zabbix是一款极其强大的开源监控工具,下面我分享下zabbix如何监控表空间,跟着这个思路,监控其他项都是类似操作. 前提条件是你已经有了zabbix server和zabbix age ...
- AspectJ 切面注解中五种通知注解:@Before、@After、@AfterRunning、@AfterThrowing、@Around
https://blog.csdn.net/u010502101/article/details/78823056
- linux 学习笔记 groupadd创建组
1> groupadd -g test2 2>usermod -d /home/test -G test2 test 3>su user 4>groups 注意:root用户才 ...
- 双11线上压测netty内存泄露
最近线上压测,机器学习模型第一次应用到线上经历双11大促.JSF微服务有报错 LEAK: ByteBuf.release() was not called before it's garbage-co ...
- php 将16进制数串转换为二进制数据的函数
/** * 将16进制数串转换为二进制数据的函数 * @param $hexdata * @return string bindata */ function ...