解决Spring Boot @Responsebody低版本ie返回json时提示下载问题 springiejson
程序员文章站
2022-03-06 09:07:08
...
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());
}
}
@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());
}
}