accept:

Spring MVC + JSON = 406 Not Acceptable

僤鯓⒐⒋嵵緔 提交于 2019-12-07 21:27:57
在开发接口时发现了一个很好玩的问题,两个接口均是restful形式,参数在URL路径中传递,返回结果形式均为json,但是在接口测试时,一个接口正常,另一个接口报错:The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.本文来分析一下其中的原因。   先介绍一下出错的接口情况,接口代码如下: /** * 验证email是否可用 * @param email * @return */ @ResponseBody @RequestMapping(value = "/emailCheck/{email}", method = RequestMethod.GET) @ApiOperation(value = "验证email是否可用", httpMethod = "GET", response = ApiResult.class, notes = "验证email是否可用") public ApiResult checkEmailValid(@ApiParam(required = true, name = "email",