在设置统一返回结构体时遇到了字符串乱码的问题,需要设置返回结构体的编码为utf-8,但是字符串需要特殊处理,新增全局配置如下
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
@Bean
public HttpMessageConverter<?> responseBodyConverter() {
StringHttpMessageConverter converter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
return converter;
}
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(responseBodyConverter());
}
}