导出excel文件接口代码示例

导出excel文件接口代码示例1.该导出接口,token不能通过请求头来传输,需要在get请求的参数中带出来2.验证token的方法除了在拦截器中统一拦截,针对get接口传参数的方式也需要单独在接口中验证。代码语言:javascript代

导出excel文件接口代码示例

导出excel文件接口代码示例

1.该导出接口,token不能通过请求头来传输,需要在get请求的参数中带出来 2.验证token的方法除了在拦截器中统一拦截,针对get接口传参数的方式也需要单独在接口中验证。

代码语言:javascript代码运行次数:0运行复制
@RequestMapping(value = "export", method = RequestMethod.GET)
    public String export(ExportReq query,HttpServletResponse response) {
        logger.info("导出Excel uri:{},param:{}","/export",query.toString());
        try{
            //业务逻辑处理,生成excel文件。
            HSSFWorkbook export = myService.export(query);
            if(export==null){
                return "success";
            }
            //设置返回的文件流
            response.setContentType("application/vnd.ms-excel");  
            response.setHeader("Content-disposition", "attachment;filename=MyExport_"+(new Date())+".xls");  
            OutputStream ouputStream = response.getOutputStream();  
            export.write(ouputStream);  
            ouputStream.flush();  
            ouputStream.close(); 
            return null;
        }catch(Exception e){
            logger.info("导出失败...",e);
            return "fail"
        }
    }
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:2024-02-05,如有侵权请联系 cloudcommunity@tencent 删除responsereturn接口excelexport

发布者:admin,转转请注明出处:http://www.yc00.com/web/1754973178a5223330.html

相关推荐

  • 导出excel文件接口代码示例

    导出excel文件接口代码示例1.该导出接口,token不能通过请求头来传输,需要在get请求的参数中带出来2.验证token的方法除了在拦截器中统一拦截,针对get接口传参数的方式也需要单独在接口中验证。代码语言:javascript代

    1月前
    200

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信