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 ...
随机推荐
- day7 [id],[is],编码
老师的笔记: 字典:dic = {'name':'alex'} 1,增 dic['k'] = 'v' 有键值对,则覆盖 setdefault 有键值对,不添加 dic.setdefault('k1', ...
- php(apache)切换版本
php(apache)切换版本 1.brew link php@7.1 2.上两行写入 ~/.bash_profile文件 3.source ~/.bash_profile 4.sudo vi /et ...
- .net面试问答
转载自:https://www.cnblogs.com/dingfangbo/p/5768991.html .net面试问答(大汇总) 原文://http://blog.csdn.net/weny ...
- P3812 【模板】线性基
P3812 [模板]线性基 理解 :线性基 类似于 向量的极大无关组,就是保持原来所有数的异或值的最小集合, 求解过程也类似,可以 O( 60 * n )的复杂度求出线性基,线性基有许多性质,例如 线 ...
- SpringBoot使用JdbcTemplate
前言 本文是对SpringBoot使用JdbcTemplate操作数据库的一个介绍,,提供一个小的Demo供大家参考. 操作数据库的方式有很多,本文介绍使用SpringBoot结合JdbcTempla ...
- BZOJ.2006.[NOI2010]超级钢琴(贪心 堆)
BZOJ 洛谷 思路和BZOJ3784一样,用前缀和+堆维护.做那题吧,不赘述啦. (没错我就是水一个AC) //54620kb 1060ms #include <queue> #incl ...
- BZOJ.4910.[SDOI2017]苹果树(树形依赖背包 DP 单调队列)
BZOJ 洛谷 \(shadowice\)已经把他的思路说的很清楚了,可以先看一下会更好理解? 这篇主要是对\(Claris\)题解的简单说明.与\(shadowice\)的做法还是有差异的(比如并没 ...
- 2017-9-14-Linux移植:加快Linux主机的启动速度
参考文章:http://www.mintos.org/skill/fast-boot.html 今天本来不打算写Blog了,Linux笔记本开机太慢了,浪费生命.何不干脆写一篇关于加快Linux主机启 ...
- [APIO2012]派遣
[APIO2012]派遣 题目大意: 给定一棵\(n(n\le10^5)\)个结点的有根树,每个点有代价\(c_i\)和权值\(l_i\),要求你选定一个结点\(k\),并在对应的子树中选取一个点集\ ...
- spring 空指针报错,Could not create connection to database server.
驱动问题,换成最近版本的mysql驱动