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·前端·笔记
阿华的代码王国4 天前
【Android】适配器与外部事件的交互
android·xml·java·前端·后端·交互
阿华的代码王国5 天前
【Android】RecyclerView复用CheckBox的异常状态
android·xml·java·前端·后端
DavieLau6 天前
C#项目WCF接口暴露调用及SOAP接口请求测试(Python版)
xml·服务器·开发语言·python·c#
曹牧6 天前
XML头部声明发送者信息的实现方法
xml
寒士obj7 天前
熟悉并使用Spring框架 - XML篇
xml·java·spring
Arva .8 天前
Spring基于XML的自动装配
xml·java·spring
fatfishccc8 天前
循序渐进学 Spring (上):从 IoC/DI 核心原理到 XML 配置实战
xml·java·数据库·spring·intellij-idea·ioc·di
fatfishccc12 天前
【MyBatis新手避坑】详解 `Could not find resource ...Mapper.xml` 错误
xml·intellij-idea·mybatis
helloworld工程师12 天前
Dubbo应用开发之基于xml的第一个Dubbo程序
xml·dubbo·safari