使用springmvc,前端發(fā)出請(qǐng)求時(shí)返回json格式時(shí),報(bào)了以上錯(cuò)誤,錯(cuò)誤碼406。
讀了參考文章后,查看spring的xml配置,是支持json格式轉(zhuǎn)換的
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>application/json</value>
</list>
</property>
</bean>
接著再回到Controller的方法里,就發(fā)現(xiàn)了問(wèn)題:第二行,把text/json改為application/json,問(wèn)題解決
@ResponseBody
@GetMapping(produces = "text/json;charset=utf-8")
public ResultVO getMethod() {
//..
}
參考文章
Spring MVC控制器用@ResponseBody聲明返回json數(shù)據(jù)報(bào)406的問(wèn)題
The resource identified by this request is only capable of generating responses with characteristics