SpringMVC 's content negotiation supports three ways:
1. Use suffixes, such as .json and .xml suffixes.
2. Use the Accept header
3. Specify through the query parameter, such as the ?format=xml parameter, indicating that data in XML format is required to be returned ( the default parameter name is format, which can be modified. )
If some or all of the above methods are enabled at the same time, the parsing order is suffix, parameter, and Accept header .
<!-- Make this available across all of Spring MVC --> <mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" /> <!-- Total customization - see below for explanation. --> <bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"> <property name="favorPathExtension" value="true" /> <property name="favorParameter" value="false" /> <property name="parameterName" value="format" /> <property name="ignoreAcceptHeader" value="false"/> <property name="useJaf" value="false"/> <property name="defaultContentType" value="text/html" /> <property name="mediaTypes"> <map> <entry key="json" value="application/json" /> <entry key="xml" value="application/xml" /> </map> </property> </bean>
favorPathExtension
The parameter indicates whether to enable suffix, the default is true . (using the form of /account/a.json , /account/a.xml )
favorParameter
The parameter indicates whether to enable request parameter recognition, the default is false . (Use the form of /account/a?format=json , /account/?format=xml )
parameterName
The parameter indicates the name of the parameter to be used, the default format , if it is configured as mediaType , the request format becomes /account/a?mediaType=json
ignoreAcceptHeader
Indicates whether to turn off the accept header recognition, the default is false , that is, the accept header recognition is enabled by default.
defaultContentType
Indicates the default MediaType of the server .
SpringMVC 4.1 New Features (2) Content Negotiation View
http://blog.csdn.net/w372426096/article/details/78429158
Spring Web MVC framework (9) XML and JSON view and content negotiation
https://www.jianshu.com/p/b6d2ea9ffd9d