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);
  }
}
相关推荐
YxVoyager5 小时前
Qt C++ :XML文件处理工具 <QXml>模块
xml·c++·qt
天若有情6735 天前
Spring配置文件XML验证错误全面解决指南:从cvc-elt.1.a到找不到‘beans‘元素声明
xml·java·spring
私人珍藏库6 天前
[Windows] 发票识别工具。支持xml、pdf、ofd文件
xml·pdf
Derrick__17 天前
Python常用内建模块——XML
xml·python
梵得儿SHI7 天前
Java 操作 XML 及动态生成报告:从解析到实战
xml·java·jaxb·dom4j·xml解析·操作xml·报告生成
张太行_9 天前
XML语言解析
xml
未来之窗软件服务10 天前
万象EXCEL开发(五)模拟excel行计算 ——东方仙盟练气期
xml·仙盟创梦ide·东方仙盟·万象excel
sun00770010 天前
网络配置config.xml的android.mk解析
android·xml
爱吃土豆的马铃薯ㅤㅤㅤㅤㅤㅤㅤㅤㅤ10 天前
mapper.xml中limit分页参数不能使用计算表达式问题
xml
余防11 天前
XXE - 实体注入(xml外部实体注入)
xml·前端·安全·web安全·html