wuzeyu
2024-05-15 fbd4cf5aeb4274938c12030e5d235c65c20c19c3
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);
    }
}