Springboot默认返回Content-Type是text/plain,如果希望所有返回接口Content-Type都改成application/json,需要配置一下。
@Configuration
public class WebConfiguration implements WebMvcConfigurer {
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.defaultContentType(MediaType.APPLICATION_JSON);
}
}
本文介绍如何在Springboot应用中修改默认响应Content-Type,通过实现WebMvcConfigurer接口并配置defaultContentType,将所有接口的返回类型设置为application/json。

436

被折叠的 条评论
为什么被折叠?



