No converter for XXX with preset Content-Type 'application/octet-stream'

org.springframework.http.converter.HttpMessageNotWritableException: No converter for [class ReturnObj] with preset Content-Type 'application/octet-stream'

參考:https://blog.csdn.net/qq_44137046/article/details/116092565

本次的接口設(shè)計為導(dǎo)入解析接口,如果導(dǎo)入信息不符合,返回一個下載文件(application/octet-stream),符合則返回貨物集合信息(application/json)。

參考上面的鏈接內(nèi)容,確實是return null 就能解決問題。

原代碼將return null寫在service層,到controller層會仍然return ReturnObj,仍然會報錯,所以將代碼搬到controller層不會報錯:

@ApiOperation(value = "貨物信息批量導(dǎo)入")

@PostMapping(value = "/readCargosExcel")

public ReturnObj<List<TCargoVO>> readExcel(@RequestParam("file") MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws IOException

{

return ReturnObj.success(tCargoService.readCargosExcel(file,request,response));

}

修改后:

@ApiOperation(value = "貨物信息批量導(dǎo)入")

@PostMapping(value = "/readCargosExcel")

public ReturnObj<List<TCargoVO>> readExcel(@RequestParam("file") MultipartFile file, HttpServletRequest request,HttpServletResponse response) throws IOException, MyException {

????ExcelImport<TCargoVO> excelImport = ExcelImport.create(file, TCargoVO::new);

????List<TCargoVO> list = excelImport.readAll();

????if (false) {

????????excelImport.response(response);

????????return null;

????}

????return ReturnObj.success(list);

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容