liurunyu
2024-06-28 4fe7ea4fbdc0c45f14d1d8de77e3424f826ba909
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package com.dy.common.webUtil;
 
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
@Configuration
public class ResponseContentTypeConfig implements WebMvcConfigurer {
 
    /**
     * Springboot请求响应头的Content-TypeContent-Type默认是text/plain,
     * 下面配置请求响应头的Content-TypeContent-Type默认为application/json
     * @param configurer
     */
    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        configurer.defaultContentType(MediaType.APPLICATION_JSON);
    }
}