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);
  }
}
相关推荐
chilavert31817 分钟前
技术演进中的开发沉思-304计算机原理:XML
xml·计算机原理
程序猿零零漆1 天前
Spring之旅 - 记录学习 Spring 框架的过程和经验(十一)基于XML方式、注解的声明式事务控制、Spring整合Web环境
xml·学习·spring
科雷软件测试2 天前
推荐几个常用的校验yaml、json、xml、md等多种文件格式的在线网站
xml·html·md·yaml
susu10830189112 天前
maven-3.9.12的conf配置settings.xml
xml·java·maven
odoo中国4 天前
如何在 Odoo 中从 XML 文件调用函数
xml·odoo·odoo开发·调用函数
阿凉07025 天前
新版本JLink安装目录中缺失JLinkDevices.xml添加方法
xml·嵌入式硬件
Knight_AL5 天前
从 QueryWrapper 到 XML:一次「报表 SQL」的重构实践
xml·sql·重构
智航GIS6 天前
9.5 XML 处理指南
xml·前端·python
像风一样的男人@6 天前
python --yolo混合文件xml和img整理
xml·python·yolo
飞舞花下12 天前
MAVEN私有仓库配置-Nexus私有仓库
xml·java·maven