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 小时前
XML的简略知识点
xml·数据库·oracle
探索java10 小时前
Spring 解析 XML 配置文件的过程(从读取 XML 到生成 BeanDefinition)
xml·java·spring·xmlbeanfactory
阿华的代码王国1 天前
【Android】相对布局应用-登录界面
android·xml·java
工藤新一OL1 天前
把xml的格式从utf-8-bom转为utf-8
xml·c#·asp.net·.netcore·visual studio
henysugar2 天前
便捷删除Android开发中XML中重复字符串资源的一个办法
android·xml
程序员编程指南2 天前
Qt XML 与 JSON 数据处理方法
xml·c语言·c++·qt·json
龚子亦3 天前
【Unity开发】数据存储——XML
xml·unity·游戏引擎·数据存储·游戏开发
海哥编程4 天前
Python 进阶(七):XML 基本操作
xml·javascript·python
胖大和尚5 天前
删除 XML 格式中双引号内的空格
xml
中游鱼5 天前
使用C#对象将WinRiver项目文件进行复杂的XML序列化和反序列化实例详解
xml·c#·序列化和反序列化·属性的序列化和反序列化·完整序列化·adcp和winriver