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);
  }
}
相关推荐
xrkhy4 小时前
java中XML的使用
xml·java·开发语言
张扬飞舞6 小时前
IntelliJ IDEA打开项目后,目录和文件都不显示,只显示pom.xml,怎样可以再显示出来?
xml·java·intellij-idea
search71 天前
配置文件介绍xml、json
xml·json
SoFlu软件机器人2 天前
Java 框架配置自动化:告别冗长的 XML 与 YAML 文件
xml·java·自动化
AI+程序员在路上3 天前
Web Service及其实现技术(SOAP、REST、XML-RPC)介绍
xml·rpc·web
DragonnAi3 天前
【目标检测标签转换工具】YOLO 格式与 Pascal VOC XML 格式的互转详解(含完整代码)
xml·yolo·目标检测
小赵面校招3 天前
SpringBoot整合MyBatis-Plus:零XML实现高效CRUD
xml·spring boot·mybatis
0wioiw04 天前
安卓基础(XML)
xml
喜欢便码5 天前
xml与注解的区别
xml·java·开发语言