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);
}