原因添加链接描述
解决方法参照添加链接描述
百度找到的原因是因为 WebMvcConfigurationSupport ,会导致springboot的自动装配编码使用 ISO8859-1,所以我们在往前端扔中文时就乱码了
解决方法
yaml文件添加
server:
tomcat:
uri-encoding: UTF-8
spring:
http:
encoding:
charset: UTF-8
enabled: true
force: true
配置类
/*
解决中文乱码问题
*/
@Bean
public HttpMessageConverter<String> responseBodyConverter() {
return new StringHttpMessageConverter(Charset.forName("UTF-8"));
}
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
super.configureMessageConverters(converters);
converters.add(responseBodyConverter());
}
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false);
}