原因返回类型排序是 application/xml 排第一位,没加依赖之前默认json排第一位
spring项目处理方式,指定json为默认返回方式
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager"/>
<bean id="contentNegotiationManager"
class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="defaultContentType" value="application/json" />
</bean>
springBoot项目javaconfig设置默认contentType, 通过 implements WebMvcconfigurer
@Configuration
public class WebInterceptorAdapter implements WebMvcConfigurer {
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.defaultContentType(MediaType.APPLICATION_JSON, MediaType.TEXT_XML, MediaType.APPLICATION_XML);
}
}
参考:https://spring.io/blog/2013/05/11/content-negotiation-using-spring-mvc