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);
  }
}
相关推荐
kgduu1 天前
js之xml处理
xml·前端·javascript
aisifang001 天前
使用 Logback 的最佳实践:`logback.xml` 与 `logback-spring.xml` 的区别与用法
xml·spring·logback
小江的记录本2 天前
【Spring Boot—— .yml(YAML)】Spring Boot中.yml文件的基础语法、高级特性、实践技巧
xml·java·spring boot·后端·spring·spring cloud·架构
青槿吖3 天前
第二篇:告别XML臃肿配置!Spring注解式IOC/DI保姆级教程,从入门到真香
xml·java·开发语言·数据库·后端·sql·spring
SEO_juper3 天前
XML Sitemap 详解:作用、意义与创建必要性
xml·.net·seo·数字营销·2026
de_wizard5 天前
【mybatis】基本操作:详解Spring通过注解和XML的方式来操作mybatis
xml·spring·mybatis
缘于自然85 天前
高通modem如何确定MBN选的是哪个carrier_policy.xml
xml·modem·mbn
jimy15 天前
字节流(XML、JSON、文件、网络、图像、加密…)必须用无符号语义unsigned char
xml·c语言·网络·json
Predestination王瀞潞6 天前
Mapper接口与XML映射文件的绑定机制(Mapper接口的动态代理实现机制)
xml·java·mybatis
MX_93596 天前
Spring的xml方式声明式事务控制
xml·java·后端·spring