spring实现模板文件下载
前台
<form id="batchModel0" method="post" action="/common/download-file" target="downLoadFile">
<table>
<tr>
<td>
<a href="#" id="downLoad">通过手机号码查询工号名称</a>
<input type="hidden" id="remoteFileName" name="remoteFile" value="通过手机号码查询工号名称.xlsx">
<button class="btnTip " href="#execlNoteSJHM" name="mouldDetail" arrow="false" id="execlMouldSJHM" type="button" />
</td>
</tr>
</table>
</form>
后台
@RequestMapping(value = "common/download-file")
public void downloadFile(String remoteFile, HttpServletResponse response) {
try {
// excel模板路径, 此模板是直接放到项目的文件夹中即可
File file =
ResourceUtils.getFile(ResourceUtils.CLASSPATH_URL_PREFIX + "resources/batch-excel/" + remoteFile);
response.reset();
response.setContentType("application/octet-stream"); // 设置response中的文件内容
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setHeader("Content-Disposition",
"inline; filename=" + new String((remoteFile).getBytes("gb2312"), "ISO8859-1"));
OutputStream os = response.getOutputStream();
InputStream is = new FileInputStream(file);
try {
byte[] bytes = new byte[1024];
while (is.read(bytes) > 0) {
os.write(bytes);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
os.flush();
is.close();
os.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
spring实现模板文件下载的更多相关文章
- Spring Boot实现文件下载功能
我们只需要创建一个控制器(Controler)文件,即Controller目录下的File_Download.java,其完整目录如下: @Controller public class File_D ...
- Spring JDBC模板类—org.springframework.jdbc.core.JdbcTemplate(转)
今天看了下Spring的源码——关于JDBC的"薄"封装,Spring 用一个Spring JDBC模板类来封装了繁琐的JDBC操作.下面仔细讲解一下Spring JDBC框架. ...
- Spring配置文件模板
模板: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://ww ...
- Spring MVC 的文件下载
在看Spring MVC文件下载之前请先看Spring MVC文件上传 地址:http://www.cnblogs.com/dj-blog/p/7535101.html 文件下载比较简单,在超链接中指 ...
- Spring 事务模板
最近项目开发中需要用到单机事务,因为项目中使用了Spring和Mybatis框架,所以通过Spring来进行事务的管理,并且记录一下事务配置的过程 第一步:配置DataSource <!-- 发 ...
- 【Spring实战】—— 15 Spring JDBC模板使用
前一篇通过对传统的JDBC的使用操作,可以体会到使用的繁琐与复杂,套句话说,是用了20%作了真正的工作,80%作了重复的工作. 那么通过本篇,可以了解如下的内容: 1 如何配置数据源 2 如何在spr ...
- IDEA中使用spring官方模板+@Controller
视图层处理http请求用@Controller时,要配合模板的使用,模板类似javaweb中的jsp,但是模板的引擎用的是 thymeleaf ,但是并不推荐. 现在的开发模式都是前后端分离,做后端只 ...
- Spring AOP Example 文件下载:
文件下载:http://files.cnblogs.com/wucg/spring_aop_excise.zip P:124 spring核心技术 P225: spring doc 可以把Advi ...
- Spring MVC实现文件下载
下载文件① 下载文件需要将byte数组还原成文件. 首先使用mybatis将数据库中的byte数组查出来,指定文件名(包括格式).然后使用OutputStream将文件输入 @RequestMapp ...
随机推荐
- HDU 1160 FatMouse's Speed(DP)
题意 输入n个老鼠的体重和速度 从里面找出最长的序列 是的重量递增时速度递减 简单的DP 令d[i]表示以第i个老鼠为所求序列最后一个时序列的长度 对与每一个老鼠i 遍历全部老鼠j 当 ...
- [Spring实战系列](19)Servlet不同版本号之间的差别
1. 2.3版本号 2.3版本号 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application ...
- android 开发中用到的工具-持续更新(码农必看)
1. vim 单文件查看改动利器(一直使用支持各种编码各种文件,各种插件),欢迎下载笔者插件 git clone https://github.com/green130181/vim-conf.git ...
- 基于docker容器搭建fastdfs分布式文件系统
本次环境的搭建参考了 https://blog.csdn.net/qq_43455410/article/details/84797814, 感谢博主. 主要流程如下: 1. 下载fastdfs镜像 ...
- Windows平台cocos2d-x 3.0 android开发环境
cocos2d-x升级到3.0后变化不小,除了API的变化(主要是函数和类名称变化,以及使用了C++11的不少特性.function/bind, lamda, std::thread-),创建和编译p ...
- vim插件:显示树形目录插件NERDTree安装 和 使用【转】
本文转载自:https://my.oschina.net/VASKS/blog/388907 下载和配置 NERDTree插件的官方地址如下,可以从这里获取最新的版本 https://github.c ...
- Ubuntu系统下实现Android工程调用独立编译的C++程序和GMP、PBC库
目的: 实现使用C++编写代码供Android工程调用.C++代码中可以使用STL库,也可以使用常用的由源码编译生成的库,如PBC.因为PBC是基于GMP库的,所以这里只记录了GMP和PBC库的编译安 ...
- Ural2040:Palindromes and Super Abilities(离线&manecher算法)
Dima adds letters s1, …, sn one by one to the end of a word. After each letter, he asks Misha to tel ...
- cookie绕过验证码登录
#coding:utf-8 ''' cookie绕过验证码登录,第一步先访问登录页面获取登录前的cookie,第二步用fiddler抓到的手动登录的cookie加入cookie中,登录成功,第三步登录 ...
- 使用java发送HTTP请求
public class Test { public static void main(String[] args) { BufferedReader in = null; String result ...