zoukankan      html  css  js  c++  java
  • 导出下载模板

      @ApiOperation(value = "下载模板")
        @GetMapping("/download")
        public void download(HttpServletRequest request, HttpServletResponse response) throws IOException, FinanceException {
            userManagementService.download(request,response);
             }
     public void download(HttpServletRequest request, HttpServletResponse response) throws IOException, FinanceException {
            InputStream inStream = getClass().getClassLoader().getResourceAsStream("excel/user.xlsx");
            if (null != inStream) {
                try {
                    // 设置输出的格式
                    response.reset();
                    response.setContentType("application/vnd.ms-excel");
                    response.addHeader("Access-Control-Allow-Origin", "*");
                    response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
                    response.addHeader("Access-Control-Allow-Headers", "Content-Type");
                    response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("excel/人员修改模板.xlsx", "UTF-8"));
                    // 循环取出流中的数据
                    byte[] b = new byte[200];
                    int len;
                    while ((len = inStream.read(b)) > 0) {
                        response.getOutputStream().write(b, 0, len);
                    }
                    inStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    if (null != inStream) {
                        try {
                            inStream.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
    
                }
            } else {
                throw new FinanceException(111,"获取excle错误,请联系管理员");
            }

  • 相关阅读:
    (多行)省略号隐藏超出范围的文本
    JSON.parse()和JSON.stringify()
    如何获取每个input的值
    禁止文字被选中
    javasctipt数据类型转换
    jq实现伸缩二级菜单
    table-layout 表格宽度不随文字改变
    VNC安装和配置
    HTML超连接的使用
    HTML图像标记
  • 原文地址:https://www.cnblogs.com/yangxiaoli/p/14250580.html
Copyright © 2011-2022 走看看