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