我有我的 ContentNegotiatingViewResolver 设置,当我有这样的请求时它工作正常:htttp://localhost:8080/api/getSubscriptions.json(它返回 JSON)或 htttp://localhost:8080/api/getSubscriptions.xml(它返回 XML)。
但是,当我尝试执行此请求(添加参数)时,htttp://localhost:8080/api/getSubscriptions?company=vivi&key=123456&carrier=1.json 返回始终是 XML。
<mvc:annotation-driven/>
<bean id="contentNegotiationManager" class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="ignoreAcceptHeader" value="true"/>
<property name="mediaTypes">
<map>
<entry key="json" value="application/json" />
<entry key="xml" value="application/xml" />
</map>
</property>
</bean>
这是我的控制器的代码:
@RequestMapping(value = "getSubscriptions", produces={"application/json", "application/xml"} )
public @ResponseBody Model getSubscriptions(
@RequestParam(value = "company", required = true) String company,
@RequestParam(value = "carrier", required = true) String carrier,
@RequestParam(value = "key", required = true) String key,
HttpServletRequest httpRequest) throws Exception { ... }
请问,当我在请求中使用参数时,Spring 识别我的媒体类型(json/xml)缺少什么?