!9 增加单个jar文件下载方法

Merge pull request !9 from yanghx/master
This commit is contained in:
yanghx 2019-01-18 15:18:52 +08:00 committed by 不忘初心
commit c9197db31c
2 changed files with 36 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package cn.jiangzeyin.controller.manage;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.jiangzeyin.common.DefaultSystemLog;
import cn.jiangzeyin.common.JsonMessage;
import cn.jiangzeyin.common.PageUtil;
@ -157,6 +158,27 @@ public class FileControl extends BaseController {
return JsonMessage.getString(200, "上传成功");
}
/**
* 下载文件
*
* @return File
*/
@RequestMapping(value = "download")
@ResponseBody
public String download() {
String id = getParameter("id");
String filename = getParameter("filename");
try {
ProjectInfoModel pim = manageService.getProjectInfo(id);
String path = pim.getLib() + filename;
File file = new File(path);
ServletUtil.write(getResponse(), file);
} catch (Exception e) {
DefaultSystemLog.ERROR().error("下载文件异常", e);
}
return "下载失败。请刷新页面后重试";
}
@RequestMapping(value = "clear")
@ResponseBody

View File

@ -33,6 +33,7 @@
## 删除按钮
<script type="text/html" id="bar_projects">
<a href="javascript:;" class="layui-btn layui-btn-sm layui-btn-danger" lay-event="delete">删除</a>
<a href="javascript:;" class="layui-btn layui-btn-sm layui-btn-normal" lay-event="download">下载</a>
</script>
<script type="text/javascript">
var id = '$id';
@ -135,8 +136,21 @@
// 删除文件
deleteFile(data);
}
if ('download' === event) {
// 下载文件
downloadFile(data);
}
});
/**
* 下载文件
* @param data
*/
function downloadFile(data) {
var url = "/file/download?id=" + data.projectid + "&filename=" + data.filename
self.location.href = url;
}
// 删除文件
function deleteFile(data) {
layer.confirm('确定删除文件 ' + data.filename + '', {title: '系统提示'}, function (index) {