关于springboot 文件的下载(下载excel模板表格)

springboot下载上传excel文件 下载静态模板 在resource目录下创建模板template/subject123.xlsx 引入poi依赖文件 <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.17</version> &lt.. 阅读详情
采用ajax方式进行下载  发现行不通
/*下载模板文件*/
function projectreview_down(title,url){
    $.ajax(
        {
            url:url,
            method:'get',
            success:function (flag) {
                alert(flag.code);
                //location.replace(location.href);
            }
        }
    );
}

 

请直接使用

 

<span class="f-l">
   <a href="/projectreview/downtemplate" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 下载模板表格</a>


//不能采用  
   <a href="javascript:;" onclick="projectreview_down('下载表格','/projectreview/downtemplate')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 下载模板表格</a>
</span>

 

 

//controller

@GetMapping(value = "/downtemplate")
@ResponseBody
public  void downTemplate(HttpServletResponse response) {
    InputStream inputStream=null;
    try {
        RestResult restResult=new RestResult();
        restResult.setSuccess(false);
        response.reset();
        response.setContentType("bin");
        response.setHeader("Content-Disposition", "attachment;filename=" + new String("销售项目评审表项目2019XXXX.xlsx".getBytes(), "ISO-8859-1"));

       ServletOutputStream outputStream = response.getOutputStream();

        inputStream= new FileInputStream(new File(ResourceUtils.getURL("classpath:").getPath()+"static/model/xs_table.xlsx"));
        byte [] buff=new byte[1024];
        int length=0;
        while((length=inputStream.read(buff))!=-1){
            outputStream.write(buff, 0, length);
        }
        if(outputStream!=null){
            outputStream.flush();
            outputStream.close();
        }
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        if(inputStream!=null){

            try {
                inputStream.close();
            } catch (IOException e) {
                log.error("关闭资源出错"+e.getMessage());
                e.printStackTrace();
            }
        }

    }

 

 

自己写的看到的,麻烦指点下。

https://blog.youkuaiyun.com/drsbbbl/article/details/105086908

https://blog.youkuaiyun.com/drsbbbl/article/details/103092726

 

 

 

 

 

 

Spring框架的Excel导入导出 spring框架,导入excel中的数据到数据库,导出数据库数据到excel文件 立即下载

相关推荐

springboot + poi导出指定格式Excel模板

springboot + poi导出指定格式Excel模板。 springboot+poi导出指定格式Excel模板,完整项目,导出即用。 poi导出Excel

Spring Boot文件下载

Spring Boot文件下载 介绍 本文介绍在Spring Boot项目中两种下载文件的方法:通过form表单方式下载和通过ajax请求文件转blob对象下载。 方法一: form表单方式下载 代码如下: function formDownload(token, parameters){ var form=(&quot;&lt;form&gt;&quot;);//...

chen子健 841

springboot+poi导出指定格式Excel模板

springboot+poi导出指定格式Excel模板,完整项目,导出即用。springboot+poi导出指定格式Excel模板,完整项目,导出即用。springboot+poi导出指定格式Excel模板,完整项目,导出即用。springboot+poi导出指定格式Excel模板,完整项目,导出即用。springboot+poi导出指定格式Excel模板,完整项目,导出即用。springboot+poi导出指定格式Excel模板,完整项目,导出即用。

详解Springboot下载Excel的三种方式

https://www.jb51.net/article/216656.htm 汇总一下浏览器下载和代码本地下载实现的3种方式。 (其实一般都是在代码生成excel,然后上传到oss,然后传链接给前台,但是我好像没有实现过直接点击就能在浏览器下载的功能,所以这次一起汇总一下3种实现方式。) 🔥1.EasyExcel–浏览器下载 1.Maven环境 ​网络上有很多maven的easyexcel版本,还是推荐alibaba的easyexcel,操作简单,代码不冗余 1 2 3 5 6 <depend

xiaoxin_su的博客 6585

SpringBoot下载xlsx模板,导出excel数据

此文件功能使用SpringBoot来编写,包括写好的前端和后端代码。 使用SpringBoot+POI导出excel数据。 使用SpringBoot导出excel模板文件,防止用户导入错误。 先看是否需要在下载,功能演示都放在这篇文章了:https://truedei.blog.youkuaiyun.com/article/details/105325018 下载地址:点我下载 项目结构 controller层 package edu.sdjsjxy.jc.controller; import com.alibaba.fastjson.JSONObject; import com.fasterxm

AUTOSAR/汽车行业

AUTOSAR架构及汽车产业链相关介绍

m0_54254513的博客 1万+

SpringBoot下载Excel文件时,报错文件损坏

我把模板文件放在了resources目录下 maven插件打包项目的时候,默认会压缩resources目录下的文件。 服务器读取的文件流来自于压缩后的文件,而返回给浏览器时,浏览器把他当作正常的文件解析,自然不能得到正确的结果。 解决方案: 配置一下maven插件,打包的时候不要压缩模板文件,排除拓展名为xlsx的文件。 <plugin> <groupId>org.apache.maven.plugins<

小楼夜听雨的博客 1315

算法 A 求稳健平均值和稳健标准差

文章目录算法原理代码 算法原理 算法 A 来自 GB/T 6379.5。应用此算法计算得到数据平均值和标准差的稳健值。稳健性是估计算法的特点,而不是其产生的估计值的特点,因此严格来说,称由此算法计算的平均值和标准差是稳健的是不确切的。然而,为避免使用繁琐的术语,“稳健均值”和“稳健标准差”应理解为利用稳健算法计算的总体均值和总体标准差的均值估计。 设数据为 xi,i∈(1,2,⋯ ,n)x_i, i\in(1,2,\cdots,n)xi​,i∈(1,2,⋯,n),记稳健平均值为 x∗,s∗x^*, s^*x

zhuo木鸟的博客 9258

springboot项目实现excel静态模板下载

excel静态模板下载,有两种方式:第一种,在http头中指定输出文件流的类型为"application/vnd.ms-excel"类型时,输出流时就不需要添加输出文件的后缀名;第二种,指定文件流的类型为"multipart/form-data"时,输出流时需要判断文件是.xls/.xlsx,并且加上后缀名。 1、方式一:(有些许问题需要改进) controller层代码:  @Get...

小屁孩大帅-保密的博客 943

Allegro PCB设计小技巧:如何用Shift键快速平移复制走线和过孔?

本文深入解析了Allegro PCB设计中利用Shift键进行平移复制的核心技巧。通过对比传统复制粘贴流程,详细演示了如何高效、精准地批量复制走线和过孔,尤其适用于创建等间距电源总线、过孔阵列等场景,能显著提升PCB设计效率与准确性。

pz89012345的博客 555

Qt代码-软件商店

ui->statusBar->showMessage(QString("%1 已卸载").arg(app["name"].toString()));ui->statusBar->showMessage(QString("开始下载 %1...").arg(app["name"].toString()));QString("%1 已下载完成,是否立即安装?ui->statusBar->showMessage(QString("%1 下载完成").arg(app["name"].toString()));

寒寒豆豆软件公司的博客 111

Vue+SpringBoot实现Excel模版上传、下载、Excel数据导出

环境准备:导入Maven依赖 <!-- hutool --> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>${hutool.version}</version>

LMGD的博客 4600

三维点云转深度图

点云投影过程是将三维点云数据转化为二维图像坐标的关键步骤,它的实现涉及到相机内外参数的计算,包括相机的内部参数(如焦距和主点)和外部参数(如相机位置和方向)。具体来说,可以通过将每个点的三维坐标转换为相机坐标系下的坐标,然后使用相机内部参数和外部参数来计算在二维图像中的坐标。接着计算每个点的深度值,将深度值映射到像素值上,最后创建深度图像并将深度值赋给对应的像素值。这里需要注意的是,在将深度值映射到像素值上时,需要将像素值转换为 uchar 类型,否则在将深度值赋给像素值时会出现类型不匹配的错误。

点云兔子的博客 3172

springboot+easypoi模板导出Excel 动态表头+多表格(一个sheet)

1.需求:导出的数据如下图所示 其中表头中的仓库 集散地是是动态生成的。 首先制作Excel模板: 代码: @Resource private RedisService redisService; @Override public void assignModel(EventInfo info, HttpServletResponse response) { AssginModelRes res=new AssginModelRes(); Object obj = redisServ

weixin_42156018的博客 4658

ResNet改进(51):基于轴向注意力机制的改进ResNet模型

本文介绍了一种结合轴向注意力机制的改进ResNet模型。 通过在传统CNN中引入轴向注意力,我们能够在保持计算效率的同时,增强模型对图像全局上下文的理解能力。这种混合架构结合了CNN的局部特征提取优势和注意力机制的全局建模能力,在图像识别任务中表现出色。 轴向注意力机制的应用不仅限于ResNet,也可以灵活地集成到其他CNN架构中。 未来可以探索更多注意力变体,或将其应用于特定领域任务,如医学图像分析、自动驾驶等需要精确空间理解的场景。 希望本文能帮助你理解如何将注意力机制与传统CNN结合,为你的计

2401_82355416的博客 359

流体动力学仿真软件:Star-CCM+_(15).用户自定义函数与模型

用户自定义函数(User-Defined Functions, UDFs)允许用户编写自己的函数,并在仿真中调用这些函数。UDFs可以用于定义复杂的边界条件、源项、材料属性等。Star-CCM+支持多种编程语言,包括C++、Fortran和Java等,其中最常用的语言是Java。用户自定义模型(User-Defined Models, UDMs)允许用户在仿真中引入自定义的物理模型。这些模型可以用于描述流体行为、化学反应、多相流等复杂现象。Star-CCM+提供了丰富的API来支持UDMs的开发。

kkchenjj的博客 556

Java操作excel之合并单元格、写入强制换行数据

1、初始化Excel表格 HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("test"); List<Object> list= 获取list String fileName = "test" + ".xls";//设置要导出的文件的名字 2、合并单元格 /...

小达哥的博客 6942

C#跨平台制图新纪元:Mapsui,一库在手,地图我有

深入学习Mapsui的渲染机制,定制属于你的地图样式,无论是颜色、图标还是文字,都可以随心所欲。

java专栏 1457

【springboot下载文件】

springboot实现文件下文和上传

layui表格处理时间 530

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

Springboot项目导出Excel静态模板

首先业务需求是这样的 在给客户开发的企业系统中需要统计一些东西,这样就需要填写不同的Excel表格,为了不让用户填写的Excel表格五花八门给开发人员造成困扰则将已经定义好的Excel模板放在系统里 好了,直接贴代码 模板放置的位置 public class DownloadExcelModelController { public Result getApplicationTemplate(H...

qq_39787941的博客 2602

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

SpringBoot导出Excel模板

文章目录SpringBoot导出Excel模板pom.xml依赖Excel模板文件Controller测试 SpringBoot导出Excel模板 共同探讨,向各位大佬学习 走向CEO,迎娶白富美 pom.xml依赖 <!--excel--> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml<

LXH_HX的博客 1977

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

SpringBoot + Vue+POI实现导入Excel到数据库与导出数据库数据到Excel表格

SpringBoot + Vue实现导入Excel到数据库与导出数据库数据到Excel表格 一、导入excel表格到数据库 (一)后端实现 1.导入POI依赖 <!--导入POI依赖,ms office文件生成--> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId>

qq_41143942的博客 3376

【Springboot7】ApachePOI文件导入导出

Excel 的表头通常是中文(如“仪器名称”),而 Java 实体的属性是英文。需要在这个方法里维护一个巨大的字典,根据传入的表名返回对应的映射关系。直接去读取项目目录下的静态 Excel 模板文件,并以文件流的形式返回给前端。版本、解析表头、动态创建对象、反射赋值与类型强转。Service 层实现。

硕士在读小菜鸟的博客 164

springboot+mybatis+mysql+jquery+easyui+ajax小模块

4 接下来在static文件下创建一个.html文件,并导入脚本路径。至于xml文件大家自己动手,上网查一下,多练习。下载包,解压缩以后放在resources目录下。5. 接下来就是body部分;6.最后就是绑定点击事件发请求部分。1.新建springboot项目。7.后端Controller。9.Service实现类。8.Service接口。10.Mapper接口。

m0_58174511的博客 753

EasyExcel 在实际项目中的使用

EasyExcel在项目中的使用

qq_50970746的博客 957

SpringBoot打成jar包部署,Excel模板下载文件

问题一. 读取resource 目录下文件时出现路径找不到 在本机测试都很顺利,当打包jar文件放到服务器上测试的时候发现了类似下面的异常信息: java.nio.file.NoSuchFileException: file:/app.jar!/BOOT-INF/classes!/xxx.xlsx 原因:spring boot 将项目打包为jar,使用 java - jar 包名 在服务器上...

zwj1030711290的优快云 1649
上一篇: 开发微信小程序post请求与get请求
下一篇: java 文件上传和下载 oss
drsbbbl
博客等级 码龄9年 19粉丝 53原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值