jackson-dataformat-xml引入使用后,响应体全是xml

解决方案:

https://spring.io/blog/2013/05/11/content-negotiation-using-spring-mvc

java 复制代码
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.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {

  /**
    *  Total customization - see below for explanation.
    */
  @Override
  public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
    configurer.favorPathExtension(false).
            favorParameter(true).
            parameterName("mediaType").
            ignoreAcceptHeader(true).
            useJaf(false).
            defaultContentType(MediaType.APPLICATION_JSON).
            mediaType("xml", MediaType.APPLICATION_XML).
            mediaType("json", MediaType.APPLICATION_JSON);
  }
}
相关推荐
祭曦念2 天前
ArkUI声明式UI入门:从XML到声明式的思维转变
xml·ui·鸿蒙
Meteors.3 天前
安卓源码阅读——01.grade设置binding为true时,xml如何进行映射
android·xml
程序员buddha3 天前
传统 Spring 框架,XML 配置 Bean 的方式
xml·java·spring
前网易架构师-高司机3 天前
带标注的交警识别数据集,可识别交警和非交警,5587张图,支持yolo,coco json,voc xml,文末有模型训练代码
xml·yolo·json·数据集·交警
波诺波4 天前
最小 SOFA XML 场景结构 0-base.scn
xml·java·前端
夕除6 天前
spring boot 14
xml·spring boot·redis
一拳一个娘娘腔7 天前
【SRC漏洞挖掘系列】第09期:XXE与反序列化 —— 当XML和Java开始“吃”代码
xml·java·安全·web安全·github
Cx330❀7 天前
【Linux网络】从以太网碰撞到 Socket 套接字与网络字节序的深度解析
xml·linux·运维·服务器·开发语言·网络·c++
缘于自然89 天前
高通modem如何确认device_config.xml的使用路径
xml·modem·mbn·mcfg
丑八怪大丑14 天前
XML_Tomcat_HTTP
xml·http·tomcat