Spring返回Json出错:HttpMessageNotWritableException

291 阅读1分钟
HttpMessageNotWritableException: No converter found for return  value of type

今天查询数据库的时候,Spring返回Json出现了标题错误。原因是查询的结果是null,在返回实体类时封装Json找不到相应的类。

Service

public ResponseEntity<Object> getRoutemap(int routeMapId) {
        // dao.getRoutemap(routeMapId)的值为null
        return setNormalResponse(dao.getRoutemap(routeMapId));
}

解决办法

new一个空的实体类并返回。