org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.http.converter.HttpMessageNotWritableException: No converter for [class com.pinzhi.dtm.common.core.util.R] with preset Content-Type 'application/vnd.ms-excel;charset=utf-8'
时间: 2023-12-10 18:03:07 浏览: 407
这个错误是由于在处理请求时,Spring MVC找不到能够将响应消息转换为指定的Content-Type的HttpMessageConverter。在你的代码中,你需要添加一个能够将com.pinzhi.dtm.common.core.util.R对象转换为application/vnd.ms-excel;charset=utf-8格式的HttpMessageConverter。你可以通过添加以下代码来解决这个问题:
```java
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
MappingJackson2HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter();
jacksonConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.valueOf("application/vnd.ms-excel;charset=utf-8")));
converters.add(jacksonConverter);
}
}
```
这段代码注册了一个MappingJackson2HttpMessageConverter实例,并将其支持的媒体类型设置为application/vnd.ms-excel;charset=utf-8。这样,在处理请求时,Spring MVC就会使用这个转换器将响应消息转换为指定的格式。
阅读全文