mem*_*und 6 java spring spring-web spring-rest
我想创建一个生成text/csv内容的简单网络服务。但我不能要求它:
@RestController
public class MyServlet {
    @PostMapping(produces = {"text/csv", "application/json"})
    public Object post() {
        //...
    }
}
spring.mvc.contentnegotiation.media-types.csv=text/csv
当我发送带有 http 标头的 post 请求时Content-Type: text/csv,出现以下错误:
415:Content type 'text/csv' not supported
这是我的配置:
@Configuration
public class ContentNegotiationConfiguration implements WebMvcConfigurer {
    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        configurer
                .favorParameter(true) //favor &format=csv
                .defaultContentType(MediaType.APPLICATION_JSON)
                .parameterName(format);
                //.mediaType("csv", new MediaType("text", "csv")) //also tried without success
    }
}
| 归档时间: | 
 | 
| 查看次数: | 10106 次 | 
| 最近记录: |