当前位置:首页 » JAVA技术教程

解决Spring Boot @Responsebody低版本ie返回json时提示下载问题

2018-03-02 14:01 本站整理 浏览(12)

Spring boot V1.5.6
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
/**
* 解决低版本ieresponsebody返回json的时候提示下载问题
* @return
*/
public MappingJackson2HttpMessageConverter customJackson2HttpMessageConverter() {
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
List<MediaType> supportedMediaTypes = new ArrayList<MediaType>();
MediaType media = new MediaType(MediaType.TEXT_HTML, Charset.forName("UTF-8"));
supportedMediaTypes.add(media);
jsonConverter.setSupportedMediaTypes(supportedMediaTypes);
return jsonConverter;
}
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(customJackson2HttpMessageConverter());
}
}