.w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation]

当想要返回的是json数据,produces写的"text/plain",会报错

@RequestMapping(value = "/getDynamicByDynamicId1",produces = "text/plain")
@ResponseBody
public Dynamic getDynamicByDynamicId1(){
System.out.println();
return dynamicMapper.getDynamicByAnnotationFromDynamicId(1l);
}

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Thu Nov 21 15:01:12 CST 2019
There was an unexpected error (type=Not Acceptable, status=406).
Could not find acceptable representation
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
 
改为
@RequestMapping(value = "/getDynamicByDynamicId1",produces = "application/json")
@ResponseBody
public Dynamic getDynamicByDynamicId1(){
System.out.println();
return dynamicMapper.getDynamicByAnnotationFromDynamicId(1l);
}
原文地址:https://www.cnblogs.com/sunupo/p/11905763.html