1、解决方案1(全局,推荐):
List fastMediaTypes = new ArrayList<>();
fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
fc.setSupportedMediaTypes(fastMediaTypes);
@Configuration
public class MvcConfiger implements WebMvcConfigurer {
/**
* 配置fastjson转换器
* @param converters
*/
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
//fastjson
FastJsonHttpMessageConverter fc = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
//中文编码格式设置 开始
List<MediaType> fastMediaTypes = new ArrayList<>();
fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
fc.setSupportedMediaTypes(fastMediaTypes);
//中文编码格式设置 结束
fc.setFastJsonConfig(fastJsonConfig);
converters.add(fc);
}
}
2、解决方案2(单个):
produces = “application/json;charset=utf-8”
@RequestMapping(
value = "/login",
produces = "application/json;charset=utf-8",
method = RequestMethod.POST
)