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);
  }
}
相关推荐
从此不归路15 小时前
Qt5 进阶【12】JSON/XML 数据协议处理:与后端/配置文件的对接
xml·开发语言·c++·qt·json
方芯半导体1 天前
EtherCAT “通信 + 控制“ 的全国产化控制方案,ESC芯片(FCE1323)与国产MCU芯片功能板解析
xml·网络·单片机·嵌入式硬件·网络协议·机器人·自动化
好好研究1 天前
总结SSM设置欢迎页的方式
xml·java·后端·mvc
R-sz3 天前
mybatis的XML,如何多值匹配,支持单值(=)和多值(IN)查询
xml·mybatis
方芯半导体3 天前
EtherCAT从站控制器芯片(FCE1353)与MCU(STM32H743)功能板解析!
xml·stm32·单片机·嵌入式硬件·物联网·自动化
码农娟3 天前
Hutool XML工具-XmlUtil的使用
xml·java
码农娟4 天前
Hutool XML工具-XmlUtil遇到标签问题
xml
草履虫建模5 天前
A02 Maven 基础配置:本地仓库、镜像、项目编码与常见问题(IDEA 实战)
xml·java·spring boot·spring·maven·intellij-idea·idea
Dawndddddd5 天前
XXE(XML外部实体注入)漏洞
xml·xxe
嵌入式老表5 天前
ISO15118-2 解读4 —— XML、EXI、签名
xml