异常
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
原因之一(自我感觉)
设定的response的contentType同实际controller层返回的对象类型不一致。
@ResponseBody
@GetMapping(value = "xxx", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public Boolean test(){
return true;
}
注意点
@ResponseBody需存在,才可复现。(可以在Controller Class上,如果不存在,会直接走视图解析器)produces定义了contentType为application/octet-stream,实际返回了true
本文探讨了在SpringMVC中遇到的org.springframework.web.HttpMediaTypeNotAcceptableException异常,主要原因是response的contentType与controller返回对象类型不匹配。通过具体代码示例,分析了@RequestBody、@GetMapping与MediaType.APPLICATION_OCTET_STREAM_VALUE的使用不当导致的问题。
4104

被折叠的 条评论
为什么被折叠?



