导出excel操作,本来用的get请求,没有问题,参数是勾选的行id,现在想改成post请求,在关闭流的时候,后台不报错,但是页面抛出错误,无法导出。请问这是什么原因,post请求和流之间使用有问题吗
部分代码
OutputStream output = response.getOutputStream();
fileName = URLEncoder.encode(fileName,"UTF-8");
response.addHeader("Content-Disposition", "inline;filename="+fileName+".xls");
response.setContentType("application/msexcel");
workbook.save(output, SaveFormat.XLSX);
output.flush();
output.close();
post请求时在output.close();执行之后报错
controller方法是void的没有返回值,我想应该是response传换出现错误了,请问这是什么原因怎么解决
@RequestMapping(value = "/exportExcelAsset", method = RequestMethod.POST)
@JsonResultAnnotation
@AssertLoginAnnotation
public void exportExcelAsset(HttpServletResponse response,
@RequestParam("categoryId") Integer categoryId,
@RequestParam("bigType") Integer bigType,
@RequestParam("query") String query) throws Exception {
String[] split = query.split(",");
Integer[] ids = new Integer[split.length];
for (int i=0;i<split.length;i++){
ids[i] = Integer.valueOf(split[i]);
}
List listCategory=getAllCategory(categoryId);
List<AssetExportView> assetExportViewList=AssetExportViewDao.instance.repository.findAllByCategoryIdInAndBigTypeAndAssetIdInAndIsDel(listCategory,bigType,ids,false);
assetExportViewService.exportToExcel(response,assetExportViewList,categoryId);
}
前端要解析json
你的借口返回的是excel
报了解析json的错误