The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers

使用springmvc,前端发出请求时返回json格式时,报了以上错误,错误码406。

读了参考文章后,查看spring的xml配置,是支持json格式转换的

<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的方法里,就发现了问题:第二行,把text/json改为application/json,问题解决

@ResponseBody
@GetMapping(produces = "text/json;charset=utf-8")
public ResultVO getMethod() {
    //..
}

参考文章

Spring MVC控制器用@ResponseBody声明返回json数据报406的问题

The resource identified by this request is only capable of generating responses with characteristics

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容