post请求关闭流之后报错

导出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();执行之后报错
image.png

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

    }
阅读 2.3k
2 个回答

前端要解析json
你的借口返回的是excel
报了解析json的错误

新手上路,请多包涵

JsonResultAnnotation是你们项目定义的注解吗?去掉即可。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题