Spring 3.2.* MVC通过Ajax获取JSON数据报406错误
问题描述:通过@ResponseBody标签返回JSON数据的方法都报406错,具体为
The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ()
百度以后,这位仁兄给了我灵感,http://digdata.me/archives/96/
原因是spring将放在responseBody的数据头写成 [text/html] ,而JSON应该是 application/json
直接在@RequestMapping修饰的方法上添加 produces="application/json"
形如:
@RequestMapping(value="/messageList",produces="application/json") public @ResponseBody List<MessageModel> messageList(Model model){ return messageService.getMessageList(); }
问题解决!!
浙公网安备 33010602011771号