我有以下简单的 Spring MVC 测试方法来使用 ResponseEntity 进行测试。
@RequestMapping(value = "/", method = RequestMethod.GET, produces= MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, String>> home(Locale locale, Model model) {
Map<String,String> returnMap = new HashMap<String,String>(2);
returnMap.put("lang1", "Java");
returnMap.put("lang2", "C++");
ResponseEntity<Map<String, String>> respEntity = new ResponseEntity<Map<String,String>>(returnMap, HttpStatus.OK);
return respEntity;
}
创建了 ResponseEntity 并且在 Eclipse 调试器中,我可以看到 ResponseEntity 对象的正文、标题和状态代码都是正确的,但是在页面中我收到以下错误:
The resource identified by this request is only capable of generating
responses with characteristics not acceptable according to the request
"accept" headers ().
如果有人能告诉我我做错了什么,我将不胜感激。