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);
  }
}
相关推荐
还算善良_5 天前
【XML生成】根据JSON格式化的报文,动态生成XML
xml·json
galaxyffang6 天前
skywalking整合logback.xml日志,日志文件出现乱码问题解决
xml·logback·skywalking
百***26637 天前
使用 Logback 的最佳实践:`logback.xml` 与 `logback-spring.xml` 的区别与用法
xml·spring·logback
864记忆7 天前
Qt 对 JSON和XML文件的操作详解
xml·qt·json
a***97687 天前
使用 Logback 的最佳实践:`logback.xml` 与 `logback-spring.xml` 的区别与用法
xml·spring·logback
chxii8 天前
MyBatis 动态 SQL,通过 XML (如 <if>、<foreach> 等)实现灵活的 SQL 拼接。
xml·sql·mybatis
weixin_448771728 天前
SpringBoot默认日志配置文件 logback.xml(log4j+logback)
xml·spring boot·logback
寒山李白8 天前
Mybatis使用教程之XML配置方式实现增删改查
xml·java·mybatis
百***26639 天前
Tomcat的server.xml配置详解
xml·java·tomcat
百***68829 天前
使用 Logback 的最佳实践:`logback.xml` 与 `logback-spring.xml` 的区别与用法
xml·spring·logback