SpringBoot乱码
SpringBoot 乱码
2023-09-14 08:58:41 时间
第一步:
第一步,约定好传参编码格式
不管是运用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; } }
相关文章
- Java项目毕业设计:基于springboot+vue的电影视频网站系统「建议收藏」
- SpringBoot的启动流程_springboot启动卡住了
- 在SpringBoot单元测试中添加参数
- SpringBoot 官方推荐,连接池,太快了!
- SpringBoot 五种获取ApplicationContext的方式
- Springboot连接mysql数据库中文乱码[通俗易懂]
- 整合Druid—SpringBoot[通俗易懂]
- springboot解决乱码,你get到了吗
- springboot启动后自动停止_redis启动停止重启
- SpringBoot内置Servlet源码解析:容器自动配置
- java SpringBoot登录验证token拦截器
- Springboot打成Jar包及引用第三方Jar包
- springboot 整合 Mybatis、JPA、Redis「建议收藏」
- SpringBoot之引导类[Application]
- Springboot集成swagger_springboot nginx
- springboot进行elasticsearch的开发
- Springboot 使用 Mybatis 启动失败排查定位
- springboot 之集成mybatis
- springboot集成过滤器
- 2-2. SpringBoot API开发详解 --SpringMVC注解+封装结果+支持跨域+打包
- 关于使用IDEA的springboot框架往Redis里写入数据乱码问题
- 《Drools7.0.0.Final规则引擎教程》Springboot+规则重新加载详解编程语言